[英]Suppress output to show only Usage and Docstring
I would like to suppress the output when using python-fire, for a given command line option. 对于给定的命令行选项,我想在使用python-fire时抑制输出。
The fire trace and everything apart from the docstring and usage is essentially useless to me and clutters up the terminal. 火灾跟踪以及除文档字符串和用法之外的所有内容对我来说基本上是无用的,并且会使终端混乱。 Any way I can get rid of it ?
有什么办法可以摆脱它?
I'm creating the cli using python-fire like this, where "command" is a function defined earlier : 我正在使用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
Expected Output: 预期产量:
$ python cli.py command1
Docstring: Does something
Usage: cli.py command1 arg1
cli.py command1 --first-arg arg1
You can achieve this by editing core.py in the python-fire library by commenting/deleting out the printing of the trace in the following if condition: 您可以通过在以下条件中注释/删除跟踪的打印,在python-fire库中编辑core.py来实现此目的:
if component_trace.HasError():
It's hacky but it works for now. 它很hacky,但目前可以使用。
The Fire trace is no longer shown by default in the latest version of Fire, starting with version v0.2.0. 从版本v0.2.0开始,默认情况下,Fire的默认版本不再显示Fire跟踪。 I think you'll find the output is much cleaner than it was in earlier versions.
我认为您会发现输出比以前的版本干净得多。
pip install -U fire
to upgrade. pip install -U fire
升级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.