-
First Check
Commit to Help
Example Codeapp = typer.Typer(add_help_option=False)
@app.callback()
def main(
ctx: typer.Context,
help: bool = typer.Option(False, "--help", "-h", help="Show this message and exit."),
):
if help:
typer.echo(ctx.get_help())
raise typer.Exit()DescriptionMany CLI tools support both --help and -h for displaying help. Currently, adding -h support in Typer requires significant boilerplate code (something like the example). I understand the current behavior is intentional, but it would be helpful to have a simpler opt-in mechanism. The current solution is quite verbose for a common use case. Something like this could be supported: app = typer.Typer(add_short_help=True)or ? app = typer.Typer(help_option_names=["--help", "-h"])Operating SystemLinux, Windows, macOS Operating System DetailsNo response Typer Version0.20.0 Python Version3.11 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
I finally found the solution in the repo in tests/test_others.py app = typer.Typer(
...,
context_settings={"help_option_names": ["-h", "--help"]},
)I was not able to find it in the documentation. It seems that it is nowhere in the documentation. |
Beta Was this translation helpful? Give feedback.
I finally found the solution in the repo in tests/test_others.py
I was not able to find it in the documentation. It seems that it is nowhere in the documentation.