google / google/python-fire

Read variables from either the CLI or from the environment

未關閉
#106 3 則留言 4 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
28.2k
分支
1.5k
PR 合併指標
30 天內沒有已合併 PR

描述

Hello,

I have been using Fire for a while now and in the last few days, it struck me that it may be nice to have a way to read a *required* variable either as an argument or as an environment variable.

The example that made me think about this was a simple script I wrote to execute some tasks in Facebook's API. It needs to receive both the _application id_ and _secret_. Sometimes I leave those as environment variables and sometimes I do not, depending on the machine that receives the deployed code.

I solved the issue by doing something like:

```python
from os import environ
from fire import Fire

APP_ID = environ.get('APP_ID')

def main(app_id=None):
assert app_id or APP_ID, 'You need to provide the app ID either as a parameter or as an environment variable'

if __name__ == '__main__':
Fire(main())
```

This got me wondering if it would be nice or even useful to implement something like this directly into Fire's variable handling. If so, I would love to contribute.

Thank you all very much :D

貢獻指南

開啟貢獻指南

研究方向

從 Fire(main()) 進入點以及函式庫的變數處理和 CLI 引數解析行為開始。釐清應如何透過引數或環境變數提供必要值、哪個來源具有優先權,以及應如何測試補全;該 issue 未指定特定的檔案或測試。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
cli
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。