• 
      

    Add base classes for multi-commands.

    Review Request #11882 — Created Nov. 24, 2021 and submitted — Latest diff uploaded

    Information

    RBTools
    master

    Reviewers

    We'll soon be adding two new commands, rbt api and 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. SubCommand should be inherited for
    each subcommand offered, and MultiCommand aggregates them together.
    Arguments from the MultiCommand are added in to the subcommand
    parsers.

    The one tricky thing here was getting --help to 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_help to default to True in the parser initialization. This
    allows us to call parse_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.

    Commits

    Files