[英]Suppress output to show only Usage and Docstring
对于给定的命令行选项,我想在使用python-fire时抑制输出。
火灾跟踪以及除文档字符串和用法之外的所有内容对我来说基本上是无用的,并且会使终端混乱。 有什么办法可以摆脱它?
我正在使用python-fire这样创建cli,其中“ command”是前面定义的函数:
if __name__ == "__main__":
fire.Fire(
{
"command": command
}
)
$ python cli.py command
Fire trace:
1. Initial component
2. Accessed property "command"
3. ('The function received no value for the required argument:)
Type: function
String form: <function list_property_versions at 0x10de5d840>
File: ./cli.py
Line: 171
Docstring: Does something
Usage: cli.py command arg1
cli.py command --first-arg arg1
预期产量:
$ python cli.py command1
Docstring: Does something
Usage: cli.py command1 arg1
cli.py command1 --first-arg arg1
您可以通过在以下条件中注释/删除跟踪的打印,在python-fire库中编辑core.py来实现此目的:
if component_trace.HasError():
它很hacky,但目前可以使用。
从版本v0.2.0开始,默认情况下,Fire的默认版本不再显示Fire跟踪。 我认为您会发现输出比以前的版本干净得多。
pip install -U fire
升级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.