我使用Typer和枕头做了一个简单的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.有办法让它失效吗?我没有在文件上找到。
发布于 2020-08-08 14:28:44
今天我遇到了同样的问题,除了在源代码中找到这个问题之外,我什么也找不到,我发现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.发布于 2022-11-09 09:30:12
从0.7.0版本开始,Typer 默认情况下不包括这些如果您使用typer.run() API的话。
示例:
# foo.py
import typer
def main():
pass
if __name__ == "__main__":
typer.run(main)生产:
$ pip install typer[all]==0.7.0
$ python foo.py --help
Usage: foo.py [OPTIONS]
╭─ Options ───────────────────────────────────────╮
│ --help Show this message and exit. │
╰─────────────────────────────────────────────────╯https://stackoverflow.com/questions/62494622
复制相似问题