.zenv
Dotenv (.env) loader written in rust 🦀
Add zenv
with a version of your choice in the Cargo.toml
toml
[dependencies]
zenv = "<version>" # Make sure it's the latest version
cargo
bash
cargo install zenv --features=cli
Check out the Release page for prebuild binaries for zenv
, available for different operating systems.
```rust fn main() { zenv::Zenv::new(".env", false).configure().ok();
// or use macro, which expands to above statement
zenv::zenv!()
} ```
Read the full documention
``` zenv Dotenv (.env) loader written in rust
USAGE:
zenv [FLAGS] [OPTIONS] --
FLAGS: -v, --version Prints version -h, --help Prints help information -x, --expand Enable variable expansion
OPTIONS: -f, --file Path to .env file
ARGS:
Examples: zenv -f .env -- node index.js zenv -f .env -- npm run dev zenv -f .env -- terraform apply ```
```bash PORT=5000 NODE_ENV=production
SQUOTE='singlequoted' DQUOTE='doublequoted' ```
Comments can be added by using #
character.
```bash
ATTHEEND=commentatthe_end # I am here
QUOTED="quote#quoted" # I'll be removed ```
New lines can added by new line (\n
) character and this only works if the values is surrounded by double quotes.
```bash PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nadflhsdlfsjkldfjklsdjf\n-----END RSA PRIVATE KEY-----"
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY----- adflhsdlfsjkldfjklsdjf asdffwejdjf983283lk -----END RSA PRIVATE KEY-----" ```
If you want to escape the new line character you can use the escape (\
)
ESCAPED="escaped\\nnew\\nline"
Zenv
also supports variable substitution (off by default) from the current file or from the operating system. Substitution only works if the values is double quoted ie.e "
and can be achieved by the following:
${VAR}
pattern (recommended)$
character, which terminates after reaching a character which is not _
or alphanumeric.```bash BASIC=basic EXPANDED='${BASIC}expanded' # expands to 'basicexpanded'
PATH
is available)SYSTEM_VARIABLE="${PATH},/this/is/new/path" ```