简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM