Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read variables from either the CLI or from the environment #106

Open
fbidu opened this issue Dec 14, 2017 · 3 comments
Open

Read variables from either the CLI or from the environment #106

fbidu opened this issue Dec 14, 2017 · 3 comments

Comments

@fbidu
Copy link

fbidu commented Dec 14, 2017

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:

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

@dbieber
Copy link
Member

dbieber commented Dec 15, 2017

See also this PR: #100
unfortunately I've been slow in getting around to it, my apologies!

@fbidu
Copy link
Author

fbidu commented Dec 15, 2017

Oh, I didn't see that PR or issue #94. Later I was wondering if we could make this injection more generic and customizable. My point is that it may be useful to read those variables from config files in .ini, .json, .yaml formats and so on.

Before I elaborate any further, should we close this issue as a duplicate of #94 ?

@fbidu
Copy link
Author

fbidu commented Jun 5, 2020

Hello, just to give a heads up, I stumbled on this issue again today. If you need help implementing something like this, let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants