0

I would like to suppress the output when using python-fire, for a given command line option.

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 :

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
Utkarsh K
  • 1
  • 2

2 Answers2

0

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:

if component_trace.HasError():

It's hacky but it works for now.

Utkarsh K
  • 1
  • 2
0

The Fire trace is no longer shown by default in the latest version of Fire, starting with version v0.2.0. I think you'll find the output is much cleaner than it was in earlier versions.

pip install -U fire to upgrade.