python-fire
python-fire copied to clipboard
How to display class functions in help?
Hey, I am using a class like:
class Foo:
def __init__(self, name):
self.name=name
@property
def info(self):
return self.name
def do_somthing(self, arg1):
return do_it(arg1)
if __name__ == '__main__':
fire.Fire(Foo)
I like to be able to see in the help the functions/properties in Foo class not only the args in the constructor. Does it possible?
Thanks
Your example seems to work fine when I tested it. Since you have a required argument name, you have to specify it.
python3 example1.py --name=foo
Output
NAME
example1.py --name=foo
SYNOPSIS
example1.py --name=foo COMMAND | VALUE
COMMANDS
COMMAND is one of the following:
do_somthing
VALUES
VALUE is one of the following:
info
name
@chey This is the output of
python example.py --help:
NAME
example.py
SYNOPSIS
example.py --name=NAME
ARGUMENTS
NAME
To rephrase the question, how can you make the built-in help command show functions/properties in Foo class and not just the options for __init__? The only way I know to make something show up is to turn it into a staticmethod.