Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/numtostr/zenv
Dotenv (.env) loader written in rust 🦀
https://github.com/numtostr/zenv
cli config crate dotenv env environment loader rust
Last synced: about 2 months ago
JSON representation
Dotenv (.env) loader written in rust 🦀
- Host: GitHub
- URL: https://github.com/numtostr/zenv
- Owner: numToStr
- License: gpl-3.0
- Created: 2021-02-15T14:53:11.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-16T22:02:23.000Z (almost 2 years ago)
- Last Synced: 2024-05-01T16:18:07.811Z (8 months ago)
- Topics: cli, config, crate, dotenv, env, environment, loader, rust
- Language: Rust
- Homepage:
- Size: 96.7 KB
- Stars: 30
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
.zenv
Dotenv (.env) loader written in rust 🦀
## ✨ Features
- Fast as it is written in rust
- Use as lib/crate or as a standalone cli
- Support variable expansion## 🚀 Installation
### Crate
Add [`zenv`](https://crates.io/crates/zenv) with a version of your choice in the `Cargo.toml`
```toml
[dependencies]
zenv = "" # Make sure it's the latest version
```### CLI
- **Using `cargo`**
```bash
cargo install zenv --features=cli
```- **Arch Linux**
```bash
# Using `yay`
yay -S zenv# Using `pamac`
pamac build zenv
```- **From binaries**
Check out the [Release page](https://github.com/numToStr/zenv/releases) for prebuild binaries for `zenv`, available for different operating systems.
## 🤞 Usage
### Crate
```rust
fn main() {
zenv::Zenv::new(".env", false).configure().ok();// or use macro, which expands to above statement
zenv::zenv!()
}
```> Read the full [documention](https:://docs.rs/zenv)
### CLI
```
zenv
Dotenv (.env) loader written in rustUSAGE:
zenv [FLAGS] [OPTIONS] -- [args]...FLAGS:
-v, --version Prints version
-h, --help Prints help information
-x, --expand Enable variable expansionOPTIONS:
-f, --file Path to .env fileARGS:
Command that needs to be executed
[args]... Arguments for the commandExamples:
zenv -f .env -- node index.js
zenv -f .env -- npm run dev
zenv -f .env -- terraform apply
```## 🙌 Good to Know
### Basic
```bash
PORT=5000
NODE_ENV=production# Single and double quotes are also supported
S_QUOTE='single_quoted'
D_QUOTE="double_quoted"
```### Comments
Comments can be added by using `#` character.
```bash
# COMMENTED=commented
AT_THE_END=comment_at_the_end # I am here# If you want # in you value then wrap the value in single or double quotes
QUOTED="quote_#_quoted" # I'll be removed
```### New Line and Escaping
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-----"# or like this
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 (`\`)
```bash
ESCAPED="escaped\\nnew\\nline"
```### Export and sourcing
You may also add export in front of each line so you can source the file in bash:
```bash
export BASIC=BASIC
```### Substitution
`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:
- Using `${VAR}` pattern (recommended)
- Starting the variable name by `$` character, which terminates after reaching a character which is not `_` or alphanumeric.```bash
BASIC=basic
EXPANDED='${BASIC}_expanded' # expands to 'basic_expanded'# System variables (assuming `PATH` is available)
SYSTEM_VARIABLE="${PATH},/this/is/new/path"
```## 🙏 Credits
- [motdotla/dotenv](https://github.com/motdotla/dotenv) (Javascript)
- [joho/godotenv](https://github.com/joho/godotenv) (Golang)
- [bkeepers/dotenv](https://github.com/bkeepers/dotenv) (Ruby)