google / google/python-fire

Completion does not work with nested commands with 'group flags'

Đang mở
#255 1 bình luận 4 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
28.2k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I'm trying to create a CLI which consists of several command groups. Commands within the command group share some common flags. In my example that is e.g. the `--namespace` flag in the `sub` command group.

I got this working. However, it breaks some fire functionality like generating command completion and a proper `--help` output.

Note that I use the class object in stead of class instances for the command groups (in contrast to [the documentation](https://google.github.io/python-fire/guide/#grouping-commands)):
```python
import fire

class Sub(object):
"""Command group which has group-flags
"""

def __init__(self, namespace='default'):
self._namespace = namespace

def command(self):
"""Run as `mycli sub command`"""
print(f"Now I return {self._namespace}")

class MyCLI(object):
"""My super fancy CLI
"""
def __init__(self, verbose=False):
# It just references the class, not an instance as shown in the docs
self.sub = Sub
# ...

if __name__ == '__main__':
fire.Fire(MyCLI, name='mycli')
```

Running a command works properly (you can even rearrange the flag):
```
$ mycli sub command
Now I return default

$ mycli sub command --namespace test
Now I return test
```

However, when running `mycli -- --completion` it will just print a completion script without any actual command completions.

It seems that my use-case is either not supported, or I have implemented it quite wrong. I'm quite new to fire and python cli tools, so I suppose the latter could definitely be the case ;-).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.