英文:
Disable rich help panel in Typer
问题
我正在尝试使用 typer
来构建一个命令行应用程序。我还在使用 rich
来进行一些格式化。然而,安装了 rich
导致 typer 使用了 rich_help_panel
。我想要禁用它,而是希望使用正常的帮助字符串格式。我该如何实现这一点?
我迄今为止尝试过的内容:
import typer
from typing_extensions import Annotated
cli = typer.Typer(rich_help_panel=None)
@cli.command()
def multiply(x: int, y: int, exp: bool = False):
"""
Multiply two numbers.
"""
if exp:
return print(x**y)
return print(x * y)
@cli.command()
def sum(x: int, y: int):
"""
Sum two numbers.
"""
return print(x + y)
@cli.callback()
def main():
"Does arithmetic"
if __name__ == "__main__":
cli()
英文:
I'm trying to use typer
to build a CLI application. I'm also using rich
to do some formatting. However having rich installed leads to typer using rich_help_panel
. I would like to disable that. I would prefer the normal formatting of the help string. How can I achieve that?
What I have tried so far:
import typer
from typing_extensions import Annotated
cli = typer.Typer(rich_help_panel=None)
@cli.command()
def multiply(x: int, y: int, exp: bool = False):
"""
Multiply two numbers.
"""
if exp:
return print(x**y)
return print(x * y)
@cli.command()
def sum(x: int, y: int):
"""
Sum two numbers.
"""
return print(x + y)
@cli.callback()
def main():
"Does arithmetic"
if __name__ == "__main__":
cli()
答案1
得分: 1
参数 rich_help_panel
用于设置如此处所述的 rich
面板标题文本。您正在寻找的功能目前还不存在,至少目前还没有。我已经提出了一个 pull request,以添加一个用于全局禁用 rich
帮助文本和 rich
追踪的设置器。如果有人阅读这篇文章想要合并这个功能,我建议根据 这里 的说明来审查我的 PR。
英文:
The parameter rich_help_panel
is for setting the rich
panel title text as described here. The functionality you are looking for doesn't exist. At least not yet. I made a pull request to add a setter to globally disable the rich
help text and the rich
traceback respectively.
If someone reading this wants to get this merged I would suggest to write a review of my PR according to this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论