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 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.
SubCommandshould be inherited for
each subcommand offered, and
MultiCommandaggregates them together.
Arguments from the
MultiCommandare added in to the subcommand
The one tricky thing here was getting
--helpto do the right thing. In
the case of
MultiCommands, 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_helpto default to
Truein the parser initialization. This
allows us to call
parse_argsand have it not fail.
I did also have to move the logging setup out of the
method, so that we wouldn't attach multiple log handlers.
Used this extensively with the upcoming review command.