Use parent parsers to define common multi-command arguments.

Review Request #12186 — Created March 22, 2022 and submitted — Latest diff uploaded

Information

RBTools
release-3.x

Reviewers

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 --help, --debug, and
--json global arguments, along with any common subparser options
defined in common_subcommand_option_list. This is shared by all
subcommands.

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 --json on
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.

Tested all rbt review commands and options (along with an upcoming fix)
and the in-progress rbt status-update rewrite. Verified that all options
worked as expected.

Also checked the help output for each main command subcommand, checking
results.

Commits

Files