dotenv-exec

Crates.iodotenv-exec
lib.rsdotenv-exec
version0.1.1
sourcesrc
created_at2019-11-29 09:08:33.285532
updated_at2019-11-29 09:34:22.018765
descriptiondotenv-exec is a thin wrapper around execpv used to execute programs with environment variables provided by one or more dotenv files on unix systems.
homepagehttps://github.com/lirsacc/dotenv-exec
repositoryhttps://github.com/lirsacc/dotenv-exec
max_upload_size
id185276
size14,972
Charles Lirsac (lirsacc)

documentation

README

dotenv-exec

Crates.io GitHub Workflow Status

Simple Rust wrapper around execpv (through std::os::unix::process::CommandExt) and dotenv-rs for unix systems.

This will execute a program populating environment variables from .env files. By default it will look up a file named .env in the current directory or any of its parents (you can disable this with --no-default) and load any env file specified with -f / --file in that order.

All formatting, substitution and ordering rules are the same as dotenv-rs.

Installation

  • Install through cargo: cargo install dotenv-exec
  • Grab binaries from the Github releases page.

Examples

$ cat <<EOT > .env
VAR_1=1
VAR_2=2
EOT

$ cat <<EOT > .env-2
VAR_1=0
VAR_3=3
EOT

# Load .env by default
$ dotenv-exec -- env | grep VAR_
VAR_1=1
VAR_2=2

# Disable this behaviour with --no-default
$ dotenv-exec --no-default -- env | grep VAR_

# dotenv-rs does not override already set values (see VAR_1), so the order in
# which files are specified is important.
$ dotenv-exec -f .env-2 -- env | grep VAR_
VAR_1=1
VAR_2=2
VAR_3=3

$ dotenv-exec --no-default -f .env-2 -f .env -- env | grep VAR_
VAR_1=0
VAR_3=3
VAR_2=2

# If you generate env file on the fly (e.g. decrypting them), you should use
# IO redirection
dotenv-exec --no-default -f <(cat .env-2) -- env | grep VAR_
VAR_1=0
VAR_3=3

Notes

  • This is a first version and there might be some changes based on how my usage evolves. Specifically I am not sure --no-default and --ignore-missing are the right defaults and I see a risk that the no override / reverse priority order behaviour could be counter intuitive.
  • As reading from strings rather than files doesn't seem supported by dotenv-rs for now this doesn't implement the -f - convention. IO redirection should work as an alternative when using dynamically generated env files.
Commit count: 15

cargo fmt