google / google/python-fire

Support for environment variables as default

Đang mở
#94 18 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ả

As I user I'd like to be able to specify some of my arguments as environment variables.

Quite often I have a single bash script performing many calls to a script written using python-fire. Many of the functions defined in the python script contain shared arguments which I am just effectively passing from my environment variables to each of the calls. Having a way to pass those through would be extremely useful.

## Desired behaviour:

Given:
```python3
$ cat run.py
import fire
def function_1(arg1, arg2=1):
print(arg1, arg2)
fire.Fire(function_1)
```

I'd like:
```bash
$ arg1=arg1 python3.6 run.py -- --use_environment
arg1 1
$ arg1=arg1env arg2=arg2env python3.6 run.py arg1 arg2 -- --use_environment
arg1 arg2
$ arg1=arg1env arg2=arg2env python3.6 run.py arg1 -- --use_environment
arg1 arg2env
$ arg1=arg1env arg2=arg2env python3.6 run.py -- --use_environment
arg1env arg2env
$ arg1=arg1env python3.6 run.py -- --use_environment
arg1env 1
```

This would be extremely useful as then I'd be able to have the following:

```bash
export HOST=mydesiredhost
./machine_manager ping -- --use_environment
./machine_manager shutdown -- --use_environment
# No need to pass --host=mydesiredhost on each command
```

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.