google / google/python-fire

[feature request] support multiple dialects for boolean parameters

Đang mở
#461 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
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ả

Consider the following code:

```python
import fire

def a(flag: bool):
if flag:
print("hooray!")
else:
print("Wanna see a flag :(")

if __name__ == '__main__': fire.Fire(a)
```

Now, the following options work as expected (print 'hooray!'):
`python a.py --flag`
`python a.py --flag=True`
`python a.py --flag=true`

However, in order to disable flag explicity the only working option is:
`python a.py --flag=False`
and the seemingly rational version
`python a.py --flag=false`
result in 'hooray' being printed as flag is parsed as a string 'false' which then casts to boolean True.

My request:
support 0, 'false' and 'no' as valid boolean arguments that all cast to False. Make this behavior optional. One way to do this is by adding a custom type to lable such flags with.

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.