Add base classes for multi-commands.
Review Request #11882 — Created Nov. 24, 2021 and submitted — Latest diff uploaded
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.