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 apiandrbt 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, andMultiCommandaggregates them together.
Arguments from theMultiCommandare added in to the subcommand
parsers.The one tricky thing here was getting
--helpto do the right thing. In
the case ofMultiCommands, 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 toTruein the parser initialization. This
allows us to callparse_argsand 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.