cli: introduce Git-like commands
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 7 Aug 2020 19:21:15 +0000 (15:21 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 7 Aug 2020 19:29:12 +0000 (15:29 -0400)
commitddfa89036a644ee14abd92e0b0281836780968c7
treea2a402db152148f1c4813efa263ba0a60c776fbd
parentc7daae61222a4bf29de6b744a4418c1b93646f39
cli: introduce Git-like commands

This patch makes the barectf CLI work with commands like Git:

    $ barectf COMMAND COMMAND-ARGS

The goal of this change is to have the `barectf` tool perform more than
tracer generation in the future. For instance, the current
`--dump-config` option should be a dedicated command instead of being
part of the generation process.

As of this patch, the only available command is `generate` (with a `gen`
alias) which does exactly what `barectf` does without an explicit
command:

    $ barectf generate config.yaml
    $ barectf config.yaml

`--help` and `--version` are "general" options; you need to put them
before the command name, if any:

    $ barectf --help
    $ barectf --version

You can also put `--help` after the command name to get this command's
help:

    $ barectf generate --help

`argpar.py` is a Python equivalent of the low-level parts of
<https://github.com/efficios/argpar> which I originally wrote for
Babeltrace 2.

While I acknowledge that it's ludicrous to write a custom argument
parser in Python considering that the standard library and PyPI packages
offer many of them, I couldn't find one which can satisfy the "default
command" use case, with this default command accepting a non-option
argument. For:

    $ barectf config.yaml

all of them indicate that `config.yaml` is not a valid command name.

Of course this is because there's ambiguity when your configuration file
happens to be named `generate` in the current working directory:

    $ barectf generate

This can also be the `generate` command with a missing configuration
file path. As of this patch, this is what happens: `barectf` prefers the
command name. It is such a corner case that I'm not spending ONE MINUTE
on it. That being said, there's a workaround:

    $ barectf ./generate

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
barectf/argpar.py [new file with mode: 0644]
barectf/cli.py
This page took 0.023042 seconds and 4 git commands to generate.