Skip to content

WIP: Added support for calling arbitrary script with .env variables provided - #105

Merged
theskumar merged 6 commits into
theskumar:masterfrom
venthur:feat/popen
Apr 5, 2018
Merged

WIP: Added support for calling arbitrary script with .env variables provided#105
theskumar merged 6 commits into
theskumar:masterfrom
venthur:feat/popen

Conversation

@venthur

@venthur venthur commented Apr 2, 2018

Copy link
Copy Markdown
Contributor

Hi,

I've started working on a feature that'll allow to use the CLI like this:

$ dotenv foo

which will parse the .env file and calls foo in a subprocess with the environment variables from .env merged with the ones from os.environ. This is similar to the behavior of ruby-dotenv.

For now everything is in dotenv/__main__ so you could easily add another console_script in setup.py. I've stopped here as I think it would probably better to merge it in the existing dotenv script, however I think the default action should be as described above, and the existing options from the dotenv script should be optional. Please let me know what you think and if and how to proceed.

@venthur venthur changed the title WIP: Added support for calling arbitrary script with .env variables provides WIP: Added support for calling arbitrary script with .env variables provided Apr 2, 2018
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-10.9%) to 81.618% when pulling ae4628e on venthur:feat/popen into fe35be1 on theskumar:master.

4 similar comments
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-10.9%) to 81.618% when pulling ae4628e on venthur:feat/popen into fe35be1 on theskumar:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-10.9%) to 81.618% when pulling ae4628e on venthur:feat/popen into fe35be1 on theskumar:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-10.9%) to 81.618% when pulling ae4628e on venthur:feat/popen into fe35be1 on theskumar:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-10.9%) to 81.618% when pulling ae4628e on venthur:feat/popen into fe35be1 on theskumar:master.

@coveralls

coveralls commented Apr 2, 2018

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.6%) to 90.875% when pulling b374c95 on venthur:feat/popen into fe35be1 on theskumar:master.

@theskumar

theskumar commented Apr 2, 2018

Copy link
Copy Markdown
Owner

Thanks, for making this feature move.

As for the integration, I would prefer to merge this to existing cli. This could be yet another command for running commands.

As for the API, it make sense to have it as:

dotenv run <path-to-executable> [-f <path-of-dotenv>]

This way it doesn't try to overwrite/conflict any existing commands. This format is also consistent with pipenv run command. Thoughts?

https://docs.pipenv.org/#other-commands

@venthur

venthur commented Apr 2, 2018

Copy link
Copy Markdown
Contributor Author

Sure, if click can deal with something like

$ dotenv run ls -lah -f <path-to-dotenv>

or

$ dotenv run git status -f <path-to-dotenv>

and is able to associate all options an params to the run part. Unfortunately I don't have much experience with click so I have to investigate.

Also, feel free to update this branch according to your suggestion if you like.

@theskumar

Copy link
Copy Markdown
Owner

This is a valid point and I'll also have to look into it. Thinking out loud, I think the solution around confusing API could be allowing -f <path-to-env> before the run and everything after run can be passed as sub-command as it is.

dotenv [-f /path/to/.env] run <executable>

@venthur

venthur commented Apr 2, 2018

Copy link
Copy Markdown
Contributor Author

This should do the trick. It works with:
dotenv run -f .foo ls -lah and stuff like dotenv run -f .foo git log --graph --oneline

@venthur

venthur commented Apr 2, 2018

Copy link
Copy Markdown
Contributor Author

Ok I think I'm done. I won't start a fight with coveralls, I believe I've covered all relevant cases. Please review.

@theskumar

Copy link
Copy Markdown
Owner

Looks awesoome!! 💟

@theskumar
theskumar merged commit b20d818 into theskumar:master Apr 5, 2018
@theskumar theskumar mentioned this pull request Apr 5, 2018
johnbergvall pushed a commit to johnbergvall/python-dotenv that referenced this pull request Aug 13, 2021
…theskumar#105)

* Added support for calling arbitrary script with .env variables provides

* Integrated everything into cli.py

* Fail properly when no command given and exit with return code of command

* Updated README

* Added tests.

* Fixed test for run w/o command
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

Successfully merging this pull request may close these issues.

3 participants