google / google/python-fire

Display parameters of the parent class

オープン
#295 コメント 1 件 リアクション 4 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Python
スター
28.2k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

説明

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:

```python3
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:

```bash
$ python3 myfile.py
NAME
myfile.py

SYNOPSIS
myfile.py --number=NUMBER

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:

```bash
$ python3 myfile.py
NAME
myfile.py

SYNOPSIS
myfile.py --number=NUMBER --name=NAME

ARGUMENTS
NUMBER
NAME

FLAGS
Flags are accepted.
```

Thanks !

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。