cros_workon: drop shared parser logic
We currently create a shared parser, attach it to the top parser (for
`cros_workon --xxx`), and then attach it to the sub-command parsers
(for `cros_workon foo --xxx`). The name "shared" implies that there is
a single instance, but that is not the case -- it gets duplicated. So
in effect, you have two independent flags with the same name that write
to the same location in the options namespace.
With newer argparse, this no longer works because of how defaults are
set. If we look at something like `cros_workon --host list`, the new
logic processes the top level first (so sets opts.host=True), and then
processes the "list" subparser, and since --host wasn't passed in, it
sets opts.host=False (as the default).
Lets drop support for passing the common options to the subparsers.
If you want to pass in --board/etc..., they have to come first. i.e.
`cros_workon list --board` no longer works. Trying to support this
ourselves is going to be kind of a pita. Lets see if anyone notices.
BUG=chromium:752212
TEST=precq passes
Change-Id: I8d87a2cc5f0064803da5314b324dd137f6f32409
Reviewed-on: https://chromium-review.googlesource.com/602254
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/scripts/cros_workon.py b/scripts/cros_workon.py
index 252ebc3..8ddee5f 100644
--- a/scripts/cros_workon.py
+++ b/scripts/cros_workon.py
@@ -19,31 +19,24 @@
def main(argv):
- shared = commandline.SharedParser()
- shared.add_argument('--board', default=cros_build_lib.GetDefaultBoard(),
+ parser = commandline.ArgumentParser(description=__doc__)
+ parser.add_argument('--board', default=cros_build_lib.GetDefaultBoard(),
help='The board to set package keywords for.')
- shared.add_argument('--host', default=False, action='store_true',
+ parser.add_argument('--host', default=False, action='store_true',
help='Uses the host instead of board')
- shared.add_argument('--remote', default='',
+ parser.add_argument('--remote', default='',
help='For non-workon projects, the git remote to use.')
- shared.add_argument('--revision', default='',
+ parser.add_argument('--revision', default='',
help='Use to override the manifest defined default '
'revision used for a project')
- shared.add_argument('--command', default='git status', dest='iterate_command',
+ parser.add_argument('--command', default='git status', dest='iterate_command',
help='The command to be run by forall.')
- shared.add_argument('--workon_only', default=False, action='store_true',
+ parser.add_argument('--workon_only', default=False, action='store_true',
help='Apply to packages that have a workon ebuild only')
- shared.add_argument('--all', default=False, action='store_true',
+ parser.add_argument('--all', default=False, action='store_true',
help='Apply to all possible packages for the '
'given command (overrides workon_only)')
- parser = commandline.ArgumentParser(description=__doc__, parents=[shared,])
-
- # Add the shared 'packages' argument after creating the main parser so that
- # it is only bound/shared with the subcommands and doesn't confuse argparse.
- shared.add_argument('packages', nargs='*',
- help='The packages to run command against.')
-
commands = [
('start', 'Moves an ebuild to live (intended to support development)'),
('stop', 'Moves an ebuild to stable (use last known good)'),
@@ -54,8 +47,10 @@
]
command_parsers = parser.add_subparsers(dest='command', title='commands')
for command, description in commands:
- command_parsers.add_parser(command, parents=(shared,), help=description,
- description=description)
+ sub_parser = command_parsers.add_parser(command, description=description,
+ help=description)
+ sub_parser.add_argument('packages', nargs='*',
+ help='The packages to run command against.')
options = parser.parse_args(argv)
options.Freeze()