Skip to content

Command CLI ArgumentsΒΆ

The same way as with a CLI application with a single command, subcommands (or just "commands") can also have their own CLI arguments:

import typer

app = typer.Typer()


@app.command()
def create(username: str):
    print(f"Creating user: {username}")


@app.command()
def delete(username: str):
    print(f"Deleting user: {username}")


if __name__ == "__main__":
    app()
fast β†’python main.py create --help
Usage: main.py create [OPTIONS] USERNAME

Options:
--help Show this message and exit.

python main.py create Camila
Creating user: Camila

python main.py delete Camila
Deleting user: Camila

restart ↻

Tip

Everything to the right of the command are CLI parameters (CLI arguments and CLI options) for that command.

Technical Details

Actually, it's everything to the right of that command, before any subcommand.

It's possible to have groups of subcommands, it's like if one command also had subcommands. And then those subcommands could have their own CLI parameters, taking their own CLI parameters.

You will see about them later in another section.

Was this page helpful?