There examples are from the excellent Typer documentation.
- The simplest Typer file (no arguments)
- With 2 CLI arguments
- With CLI arguments and CLI options
- CLI option with a value
- Document your app
- Alternative CLI argument declaration
- Optional CLI argument
- Optional CLI argument with a Static default value
- Optional CLI argument with a Dynamic default value
- CLI argument with Help
- CLI argument with Help and Defaults
- CLI argument with Help and Hidden Default
- CLI argument with Help and Custom String Default
- CLI argument with Help and Custom Help Name (
metavar
) - CLI argument with Help Panels (via
rich
) - CLI argument - you can hide it
- CLI argument - reading an environment variable
- CLI argument - multiple environment variables
- CLI argument - hide environment variable from help text
- CLI option with Help
- CLI option with Help Panels (via
rich
) - CLI option with Hidden Default
- CLI option - make it Required
- CLI option Prompt
- CLI option with Customised Prompt
- CLI option with Confirmation Prompt
- CLI option with Password (hidden) Prompt
- CLI option with Custom Name
- CLI option with Custom Name and Short Name
- CLI option with Short Name Only
- CLI option with Short Name and Default Name
- CLI option with multiple Short Names Together
- CLI option with Callback for validation
At this point in the tutorial there were examples about TAB completion using typer-cli
. Although I followed the instructions, I couldn't get this to work on Windows or Mac so I'm leaving it out for now. Note if you install it and run typer --install-completion
, it will alter your powershell
or zsh
startup.
This section also introduced the click Context
which you get access to by declaring a function parameter of type typer.Context
. I expect this will be revisited with later examples.
- CLI option - accessing the
CallbackParam
object - CLI option - first version of
--version
- CLI option - showing the flaw in first
--version
- CLI option - a better version of
--version
I noticed that --help
for an explicit application shows --install-completion
and --show-completion
. I'm not currently using completion as I had issues so it might be nice if those options could be hidden.
- Commands - a CLI application with multiple commands
- Command CLI Arguments
- Command Options (and Command CLI Arguments)
- Command Help
- Command Help - Overwriting it
- Command Deprecation
- Command Add formatting with Rich Markup
- Command Add formatting with Rich Markdown
- Command Help Panels for Commands
- Command Help Panels for CLI Parameters
- Command Help - add an Epilog
- Command Custom Name
- Command Callback for main CLI parameters
- Command Callback on Creation
- Command Callback - Overriding Callback
- Command Callback - Only for documentation
- Command One or Multiple Commands - One
- Command One or Multiple Commands - Multiple
- Command One or Multiple Commands - One as a command/subcommand
- Command One or Multiple Commands - One with callback documentation
- Command Context - how to access it
- Command Context - executable callback
- Command Context - exclusive executable callback
- Command Context - configuring the context
- Parameter Types - intro
- Parameter Types - validation: min and max
- Parameter Types - clamping numbers
- Parameter Types - Counter CLI options
- Parameter Types - Boolean CLI options. Customise name to disable --no-something
- Parameter Types - Boolean CLI options. Alternate names e.g. --accept and --reject
- Parameter Types - Boolean CLI options. Short names e.g. -f and -F
- Parameter Types - Boolean CLI options. Only names for False
- Parameter Types - UUID CLI options
- Parameter Types - datetime CLI options default formats
- Parameter Types - datetime CLI options custom formats
- Parameter Types - Enum CLI options for predefined choices
- Parameter Types - Enum CLI options Case Insensitive
- Parameter Types - Enum CLI options List of Values
- Parameter Types - Path CLI options
- Parameter Types - Path CLI validations
- Parameter Types - File CLI FileText reading
- Parameter Types - File CLI FileText writing
- Parameter Types - File CLI FileBinaryRead
- Parameter Types - File CLI FileBinaryWrite
- Parameter Types - File CLI File Advanced Parameters
- Parameter Types - File CLI Custom Type - with Type Parser
- Parameter Types - File CLI Custom Type - with Click Custom Type
The core idea is to add a typer.Typer()
app inside another.
We start with a small app to manage items. Then we find we need to manage users. So we create a third app to tie them together:
note that we are composing here. items.py
and users.py
work as both individual apps and as command groups for app1.py