【问题标题】:Python: How to remove default options on Typer CLI?Python:如何删除 Typer CLI 上的默认选项?
【发布时间】:2020-10-11 03:29:40
【问题描述】:

我使用TyperPillow 制作了一个简单的CLI 来更改图像不透明度,而这个程序只有一个选项:不透明度。

但是当我运行 python opacity.py --help 时,它给了我两个 typerCLI 选项:

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.

有办法禁用它吗?我在文档上没有找到。

【问题讨论】:

    标签: python python-imaging-library typer


    【解决方案1】:

    我今天遇到了同样的问题,除了这个问题我找不到任何东西所以潜入源代码中以找到 Typer 如何在应用程序中自动添加这一行,所以我在 Typer 初始化时找到了这个它本身会自动将add_completion 设置为True

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

    所以当你初始化你的应用时,你可以添加这个

    app = typer.Typer(add_completion=False)
    

    这是添加add_completion=False后的样子

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多