Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display parameters of the parent class #295

Open
anth2o opened this issue Oct 29, 2020 · 1 comment
Open

Display parameters of the parent class #295

anth2o opened this issue Oct 29, 2020 · 1 comment

Comments

@anth2o
Copy link

anth2o commented Oct 29, 2020

I would like to build objects that I can instantiate and call directly from a CLI. But I want to have a base class, that I can inherit from for other classes to add new arguments. Here is a minimal example:

import fire


class A:

    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name


class B(A):

    def __init__(self, number, **kwargs):
        super().__init__(**kwargs)
        self.number = number

    def __call__(self):
        print(f"{self.name} + {self.number}")


if __name__ == "__main__":
    fire.Fire(B)

I can use this file to do python3 myfile.py --name foo --number 10 and this prints me in my terminal foo + 10. But, I would like to display the help of the CLI in a terminal, and when I do that, only the parameters of class B are displayed, and not the one from class A:

$ python3 myfile.py
NAME
    myfile.py

SYNOPSIS
    myfile.py --number=NUMBER <flags>

ARGUMENTS
    NUMBER

FLAGS
    Flags are accepted.

Do you know if I can bring slight modifications to my program so that the help displayed looks like:

$ python3 myfile.py
NAME
    myfile.py

SYNOPSIS
    myfile.py --number=NUMBER --name=NAME <flags>

ARGUMENTS
    NUMBER
    NAME

FLAGS
    Flags are accepted.

Thanks !

@MaleicAcid
Copy link

+1 really need this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants