pythonpython-imaging-librarytyper

Python: How to remove default options on Typer CLI?


I made a simple CLI using Typer and Pillow to change image opacity and this program only have one option: opacity.

But when I run python opacity.py --help it gives me the two typerCLI options:

Options:
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified
                                  shell.

  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified
                                  shell, to copy it or customize the
                                  installation.

  --help                          Show this message and exit.

There's a way to disable it? I didn't find on docs.


Solution

  • I met the same problem today, i couldn't find anything except this question so dived in the source to find how Typer automatically adds this line in app, so i found this, when Typer initialiazing itself it automatically sets add_completion to True

    class Typer:
        def __init__(add_completion: bool = True)
    

    So when you initialiazing your app you can add this

    app = typer.Typer(add_completion=False)
    

    This is how it looks after you add add_completion=False

    Usage: main.py [OPTIONS] COMMAND [ARGS]...
    
    Options:
      --help  Show this message and exit.