Add base classes for multi-commands.
Review Request #11882 — Created Nov. 24, 2021 and submitted
We'll soon be adding two new commands,
rbt api
andrbt review
, which
both want to implement additional subcommands (rbt api get
,
rbt review publish
, etc). This change adds the framework to do so,
consisting of two new base classes.SubCommand
should be inherited for
each subcommand offered, andMultiCommand
aggregates them together.
Arguments from theMultiCommand
are added in to the subcommand
parsers.The one tricky thing here was getting
--help
to do the right thing. In
the case ofMultiCommand
s, we need to actually parse the arguments in
order to get the right subparser, but doing so was enforcing any usage
requirements. It turns out that the correct fix here was to allow
add_help
to default toTrue
in the parser initialization. This
allows us to callparse_args
and have it not fail.I did also have to move the logging setup out of the
initialize
method, so that we wouldn't attach multiple log handlers.
Used this extensively with the upcoming review command.
Summary | ID |
---|---|
9c1d7311adb3f3f81f9fb99822dc2da918323c2e |
Description | From | Last Updated |
---|---|---|
Can we modernize the docs while here? |
chipx86 | |
Can we name this BaseSubCommand? |
chipx86 | |
Is this a default help text, or turning off help text? Can we add a comment/doc comment? |
chipx86 | |
This is missing a docstring. |
chipx86 | |
Can we name this BaseMultiCommand? |
chipx86 | |
Needs a double backtick, or it will be a reference. Or, ideally: :command:`rbt review ` |
chipx86 | |
, optional |
chipx86 | |
What happens if this triggers an argument parsing error condition (like an invalid argument)? Those result in a sys.exit, which … |
chipx86 | |
F821 undefined name 'SubCommand' |
reviewbot | |
F821 undefined name 'MultiCommand' |
reviewbot | |
"review groups" or "option groups"? |
chipx86 | |
Missing Args:, *args, and **kwargs. |
chipx86 | |
Should be in sorted alphabetical order (capitalized is first). |
chipx86 |
- Commits:
-
Summary ID 6180547375f99384d56926c0a451d843a6f5c66f 18a029ec319184099954b19bb70f435decd7cefc - Diff:
-
Revision 2 (+368 -20)
- Commits:
-
Summary ID 18a029ec319184099954b19bb70f435decd7cefc 1b235b2d7d82590fa3b80f309ab4dff59df1408a - Diff:
-
Revision 3 (+370 -20)
Checks run (2 succeeded)
- Commits:
-
Summary ID 1b235b2d7d82590fa3b80f309ab4dff59df1408a 9c1d7311adb3f3f81f9fb99822dc2da918323c2e - Diff:
-
Revision 4 (+384 -20)