Use parent parsers to define common multi-command arguments.
Review Request #12186 — Created March 21, 2022 and submitted
This updates the multi-command argument parsing code to leverage parent
argparsers. This is a method of defining common sets of arguments that
can be populated once up-front and then used by other argument parsers,
avoiding duplication and in theory helping with option resolution.
We now define a common option parser for the
--jsonglobal arguments, along with any common subparser options
common_subcommand_option_list. This is shared by all
This isn't really fundamentally different than re-creating the options,
like we were doing before, but it does better define how options are
expected to be shared and reduces the work that must be done at argument
parser creation time.
Originally, the global options were also being shared with the main
argument parser, but this ended up causing problems where
the main command would override that on the subcommand. This could be
solved by unsetting defaults for any global options and marking the
default as "suppress", but this was invasive (requiring other commands
to check for the presence of
options.json_output) and probably not
worth doing. So for now, only subcommands share the options.
rbt reviewcommands and options (along with an upcoming fix)
and the in-progress
rbt status-updaterewrite. Verified that all options
worked as expected.
Also checked the help output for each main command subcommand, checking
Removed the global options from the main parser, due to
argparsehandling them poorly.
Revision 2 (+40 -22)