python-fire icon indicating copy to clipboard operation
python-fire copied to clipboard

How to display class functions in help?

Open ophir-oneview opened this issue 3 years ago • 2 comments

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

ophir-oneview avatar Jan 26 '22 10:01 ophir-oneview

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 avatar Feb 01 '22 13:02 chey

@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.

jjorissen52 avatar Sep 10 '22 02:09 jjorissen52