Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 494
Zoey Avatar asked Jun 21 '20 05:06

Zoey


1 Answers

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.
like image 145
Yagiz Degirmenci Avatar answered Nov 06 '22 08:11

Yagiz Degirmenci