cli/command: Make device argument named by default.
The standard way to build the device argument required it to be
a positional argument. Positional is less flexible and predictable
long term, make it named for future commands.
BUG=chromium:1045508
TEST=run_tests
Change-Id: Iccb02acb1c2a3deb971d32887ebd57fa9055aef0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2057367
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Alex Klein <saklein@chromium.org>
diff --git a/cli/command.py b/cli/command.py
index 9030b53..b756e77 100644
--- a/cli/command.py
+++ b/cli/command.py
@@ -132,7 +132,8 @@
parser.set_defaults(command_class=cls)
@classmethod
- def AddDeviceArgument(cls, parser, schemes=commandline.DEVICE_SCHEME_SSH):
+ def AddDeviceArgument(cls, parser, schemes=commandline.DEVICE_SCHEME_SSH,
+ positional=False):
"""Add a device argument to the parser.
This standardizes the help message across all subcommands.
@@ -140,6 +141,7 @@
Args:
parser: The parser to add the device argument to.
schemes: List of device schemes or single scheme to allow.
+ positional: Whether it should be a positional or named argument.
"""
help_strings = []
schemes = list(cros_build_lib.iflatten_instance(schemes))
@@ -155,9 +157,14 @@
'e.g. servo:port:1234 or servo:serial:C1230024192.')
if commandline.DEVICE_SCHEME_FILE in schemes:
help_strings.append('Target a local file with file://path.')
- parser.add_argument('device',
- type=commandline.DeviceParser(schemes),
- help=' '.join(help_strings))
+ if positional:
+ parser.add_argument('device',
+ type=commandline.DeviceParser(schemes),
+ help=' '.join(help_strings))
+ else:
+ parser.add_argument('-d', '--device',
+ type=commandline.DeviceParser(schemes),
+ help=' '.join(help_strings))
def Run(self):
"""The command to run."""