Support for environment variables as default
- 主要語言
- Python
- 星號
- 28.2k
- 分支
- 1.5k
- PR 合併指標
- 30 天內沒有已合併 PR
描述
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
```
貢獻指南
研究方向
使用五個命令範例作為驗收案例,從 Python Fire 的 CLI 引數解析進入點開始。確定環境值應如何與位置引數和預設值互動,然後驗證明確指定的引數具有優先權,並確認文件中所述的 --use_environment 流程會產生所示結果。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- cli
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100