I have a complex CLI with a number of commands, each of which uses a Typer instance as described in the docs. One of those commands runs another external command which has its own arguments, but also has a default behaviour if no arguments are passed. I would like to pass all arguments to that command without trying to define them explicitly in my code.
My code looks something like this, using banana as the external subcommand I want to run. In mycli.py:
app = typer.Typer()
app.add_typer(banana.app, name="banana", help="Run the banana command")
then in banana.py I want something like this:
app = typer.Typer()
def default(<with an optional list of arguments>):
# TODO run the banana command with all arguments passed to it
# or nothing if no arguments were passed
More specifically, the command I am trying to run is inside a Docker image.
How do I do this?
I went through many iterations before I figured it out. In
banana.py:The above code (fully typed!) means I can run commands like the following:
and it all works as expected!
Suggestions for improvement would be greatly appreciated.
NB. This question is similar to this one but is not quite the same. And this issue was helpful too.