Commit 0895b752 authored by maruel@chromium.org's avatar maruel@chromium.org

Move the parser creation code in its own function to enable unit testing.

Unit test follow in next CL.

R=dpranke@chromium.org
BUG=
TEST=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@98480 0039d316-1c4b-4281-b951-d872f2087c98
parent 943b1273
......@@ -1229,24 +1229,8 @@ def GenUsage(parser, command):
parser.epilog = getattr(obj, 'epilog', None)
def Main(argv):
"""Doesn't parse the arguments here, just find the right subcommand to
execute."""
if sys.hexversion < 0x02050000:
print >> sys.stderr, (
'\nYour python version is unsupported, please upgrade.\n')
try:
# Make stdout auto-flush so buildbot doesn't kill us during lengthy
# operations. Python as a strong tendency to buffer sys.stdout.
sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
# Make stdout annotated with the thread ids.
sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout)
# Do it late so all commands are listed.
# Unused variable 'usage'
# pylint: disable=W0612
CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([
' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip())
for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')]))
def Parser():
"""Returns the default parser."""
parser = optparse.OptionParser(version='%prog ' + __version__)
parser.add_option('-j', '--jobs', default=1, type='int',
help='Specify how many SCM commands can run in parallel; '
......@@ -1290,6 +1274,28 @@ def Main(argv):
parser.parse_args = Parse
# We don't want wordwrapping in epilog (usually examples)
parser.format_epilog = lambda _: parser.epilog or ''
return parser
def Main(argv):
"""Doesn't parse the arguments here, just find the right subcommand to
execute."""
if sys.hexversion < 0x02050000:
print >> sys.stderr, (
'\nYour python version is unsupported, please upgrade.\n')
try:
# Make stdout auto-flush so buildbot doesn't kill us during lengthy
# operations. Python as a strong tendency to buffer sys.stdout.
sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
# Make stdout annotated with the thread ids.
sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout)
# Do it late so all commands are listed.
# Unused variable 'usage'
# pylint: disable=W0612
CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([
' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip())
for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')]))
parser = Parser()
if argv:
command = Command(argv[0])
if command:
......
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