Import the other Python modules (the files users.py and items.py).
Create the main typer.Typer() application.
Use app.add_typer() to include the app from items.py and users.py, each of those 2 was also created with typer.Typer().
Define a name with the command that will be used for each of these "sub-Typers" to group their own commands.
And now your CLI program has 2 commands:
users: with all of the commands (subcommands) in the app from users.py.
items with all the commands (subcommands) in the app from items.py.
Check it:
fast →💬 Check the helppython main.py --help Usage: main.py [OPTIONS] COMMAND [ARGS]...
Options: --install-completion Install completion for the current shell. --show-completion Show completion for the current shell, to copy it or customize the installation. --help Show this message and exit.
Now you have a CLI program with commands items and users, and they in turn have their own commands (subcommands).
Let's check the items command:
fast →💬 Check the help for itemspython main.py items --help 💬 It shows its own commands (subcommands): create, delete, sellUsage: main.py items [OPTIONS] COMMAND [ARGS]...
You can just create typer.Typer() apps and add them inside one another.
And you can do that with any levels of commands that you want.
Do you need sub-sub-sub-subcommands? Go ahead, create all the typer.Typer()s you need and put them together with app.add_typer().
In the next sections we'll update this with more features, but you already have the core idea.
This way, in the same spirit of Click, Typer applications are composable, each typer.Typer() can be a CLI app by itself, but it can also be added as a command group to another Typer app.