Option with aliases
Overview
You can provide multiple aliases for an option. This is helpful when multiple expressions are common for the same concept.
Simple Option with Multiple Aliases
An option that accepts both --directory
and --dir
:
@app.command()
def create(
directory: Optional[Path] = typer.Option(
None, "--directory", "--dir", help="The directory of the page."
),
):
Option with Full-Length and Short Name
An option that accepts both --all
and -a
:
CLIG's recommendation regarding short names:
Only use one-letter flags for commonly used flags, particularly at the top-level when using subcommands. That way you don’t “pollute” your namespace of short flags, forcing you to use convoluted letters and cases for flags you add in the future.
bool
Option with Multiple Aliases
By default, a bool
option defines one name for the True
value and one for the False
value. see Bool Option
You can also define a bool
option with 2 names both for the True
and the False
value:
@app.command()
def create(
interactive_option: bool = typer.Option(
True,
"--interactive/--no-interactive",
"--input/--no-input",
help="Switch whether interactive prompts are shown. Use `--no-input` when you call this command from scripts.",
)
):