cros: Fix bug in GetOptions() and refactoring.
cros.GetOptions() was incorrectly using a module name as a conditional
check instead of a parameter name. This CL fixes the conditional and
refactors slightly to clarify logical flow.
Also removes the call to command.GetToolset() since `cros` is once again
the only toolset.
BUG=chromium:507323
TEST=cbuildbot/run_tests
TEST=manual `cros` testing
Change-Id: I39cb3b32c8984e93d0cef082e9628ec71e9b3438
Reviewed-on: https://chromium-review.googlesource.com/283654
Reviewed-by: David Pursell <dpursell@chromium.org>
Tested-by: David Pursell <dpursell@chromium.org>
Commit-Queue: David Pursell <dpursell@chromium.org>
diff --git a/scripts/cros.py b/scripts/cros.py
index 81175d3..5ecb413 100644
--- a/scripts/cros.py
+++ b/scripts/cros.py
@@ -24,20 +24,26 @@
def GetOptions(my_commands):
- """Returns the argparse to use for commandline parsing."""
- parser = commandline.ArgumentParser(caching=True, default_log_level='notice')
- if not command:
- return parser
+ """Returns the parser to use for commandline parsing.
- subparsers = parser.add_subparsers(title='Subcommands')
- for cmd_name, class_def in sorted(my_commands.iteritems(),
- key=lambda x: x[0]):
- epilog = getattr(class_def, 'EPILOG', None)
- sub_parser = subparsers.add_parser(
- cmd_name, description=class_def.__doc__, epilog=epilog,
- caching=class_def.use_caching_options,
- formatter_class=commandline.argparse.RawDescriptionHelpFormatter)
- class_def.AddParser(sub_parser)
+ Args:
+ my_commands: A dictionary mapping subcommand names to classes.
+
+ Returns:
+ A commandline.ArgumentParser object.
+ """
+ parser = commandline.ArgumentParser(caching=True, default_log_level='notice')
+
+ if my_commands:
+ subparsers = parser.add_subparsers(title='Subcommands')
+ for cmd_name in sorted(my_commands.iterkeys()):
+ class_def = my_commands[cmd_name]
+ epilog = getattr(class_def, 'EPILOG', None)
+ sub_parser = subparsers.add_parser(
+ cmd_name, description=class_def.__doc__, epilog=epilog,
+ caching=class_def.use_caching_options,
+ formatter_class=commandline.argparse.RawDescriptionHelpFormatter)
+ class_def.AddParser(sub_parser)
return parser
@@ -74,8 +80,7 @@
raise
except Exception as e:
code = 1
- logging.error('%s %s failed before completing.',
- command.GetToolset(),
+ logging.error('cros %s failed before completing.',
subcommand.command_name)
if namespace.debug:
raise