Commit f0fc9916 authored by maruel@chromium.org's avatar maruel@chromium.org

Options cleanup, enforce nohooks and deps_os are always defined.

Review URL: http://codereview.chromium.org/2776006

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@49554 0039d316-1c4b-4281-b951-d872f2087c98
parent 116704f2
...@@ -1090,27 +1090,33 @@ def Main(argv): ...@@ -1090,27 +1090,33 @@ def Main(argv):
' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip()) ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip())
for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')])) for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')]))
parser = optparse.OptionParser(version='%prog ' + __version__) parser = optparse.OptionParser(version='%prog ' + __version__)
parser.add_option("-v", "--verbose", action="count", default=0, parser.add_option('-v', '--verbose', action='count', default=0,
help="Produces additional output for diagnostics. Can be " help='Produces additional output for diagnostics. Can be '
"used up to three times for more logging info.") 'used up to three times for more logging info.')
parser.add_option("--gclientfile", metavar="FILENAME", parser.add_option('--gclientfile', dest='config_filename',
dest="config_filename", default=os.environ.get('GCLIENT_FILE', '.gclient'),
default=os.environ.get("GCLIENT_FILE", ".gclient"), help='Specify an alternate %default file')
help="Specify an alternate .gclient file")
# Integrate standard options processing. # Integrate standard options processing.
old_parser = parser.parse_args old_parser = parser.parse_args
def Parse(args): def Parse(args):
(options, args) = old_parser(args) (options, args) = old_parser(args)
level = None
if options.verbose == 2: if options.verbose == 2:
logging.basicConfig(level=logging.INFO) level = logging.INFO
elif options.verbose > 2: elif options.verbose > 2:
logging.basicConfig(level=logging.DEBUG) level = logging.DEBUG
options.entries_filename = options.config_filename + "_entries" logging.basicConfig(level=level,
format='%(module)s(%(lineno)d) %(funcName)s:%(message)s')
options.entries_filename = options.config_filename + '_entries'
if not hasattr(options, 'revisions'): if not hasattr(options, 'revisions'):
# GClient.RunOnDeps expects it even if not applicable. # GClient.RunOnDeps expects it even if not applicable.
options.revisions = [] options.revisions = []
if not hasattr(options, 'head'): if not hasattr(options, 'head'):
options.head = None options.head = None
if not hasattr(options, 'nohooks'):
options.nohooks = True
if not hasattr(options, 'deps_os'):
options.deps_os = None
return (options, args) return (options, args)
parser.parse_args = Parse parser.parse_args = Parse
# We don't want wordwrapping in epilog (usually examples) # We don't want wordwrapping in epilog (usually examples)
...@@ -1118,18 +1124,18 @@ def Main(argv): ...@@ -1118,18 +1124,18 @@ def Main(argv):
if argv: if argv:
command = Command(argv[0]) command = Command(argv[0])
if command: if command:
# "fix" the usage and the description now that we know the subcommand. # 'fix' the usage and the description now that we know the subcommand.
GenUsage(parser, argv[0]) GenUsage(parser, argv[0])
return command(parser, argv[1:]) return command(parser, argv[1:])
# Not a known command. Default to help. # Not a known command. Default to help.
GenUsage(parser, 'help') GenUsage(parser, 'help')
return CMDhelp(parser, argv) return CMDhelp(parser, argv)
except gclient_utils.Error, e: except gclient_utils.Error, e:
print >> sys.stderr, "Error: %s" % str(e) print >> sys.stderr, 'Error: %s' % str(e)
return 1 return 1
if "__main__" == __name__: if '__main__' == __name__:
sys.exit(Main(sys.argv[1:])) sys.exit(Main(sys.argv[1:]))
# vim: ts=2:sw=2:tw=80:et: # vim: ts=2:sw=2:tw=80:et:
...@@ -119,13 +119,15 @@ class GClientSmoke(GClientSmokeBase): ...@@ -119,13 +119,15 @@ class GClientSmoke(GClientSmokeBase):
def testHelp(self): def testHelp(self):
"""testHelp: make sure no new command was added.""" """testHelp: make sure no new command was added."""
result = self.gclient(['help']) result = self.gclient(['help'])
self.assertEquals(1197, len(result[0])) # Roughly, not too short, not too long.
self.assertTrue(1000 < len(result[0]) and len(result[0]) < 2000)
self.assertEquals(0, len(result[1])) self.assertEquals(0, len(result[1]))
self.assertEquals(0, result[2]) self.assertEquals(0, result[2])
def testUnknown(self): def testUnknown(self):
result = self.gclient(['foo']) result = self.gclient(['foo'])
self.assertEquals(1197, len(result[0])) # Roughly, not too short, not too long.
self.assertTrue(1000 < len(result[0]) and len(result[0]) < 2000)
self.assertEquals(0, len(result[1])) self.assertEquals(0, len(result[1]))
self.assertEquals(0, result[2]) self.assertEquals(0, result[2])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment