envy-merge
is a CLI tool to intelligently merge multiple .env
files while ensuring that a priority file (if provided) takes precedence over all others.
- Merges multiple
.env
files into a single output. - Respects a priority file (if provided), ensuring its variables are never overwritten.
- Later files overwrite earlier ones unless the variable exists in the priority file.
- Supports output redirection to a file or prints to stdout.
- Dry-run mode to preview merged output without saving.
Ensure you have Rust installed. If not, install it via Rustup.
Clone the repository and navigate to the project folder:
git clone https://github.com/morlim/envy-merge.git
cd envy-merge
Then, build the project:
cargo build --release
Run the CLI tool with multiple .env
files:
./target/release/envy-merge file1.env file2.env
USAGE:
envy-merge [OPTIONS] <FILES>...
ARGS:
<FILES>... List of .env files to merge (at least 2 required)
OPTIONS:
-p, --priority <FILE> File to take priority in case of conflicts
-o, --output <FILE> Output .env file (default: stdout)
-d, --dry-run Show merged output without writing to a file
-h, --help Show help message
-V, --version Show version
DB_HOST=secure-db
DB_PORT=5432
API_KEY=supersecret
DB_HOST=localhost
DB_PORT=3306
DEBUG=false
API_KEY=publickey
LOG_LEVEL=info
./target/release/envy-merge -p priority.env file1.env file2.env
DB_HOST=secure-db # Taken from priority file (CANNOT be overwritten)
DB_PORT=5432 # Taken from priority file (CANNOT be overwritten)
API_KEY=supersecret # Taken from priority file (CANNOT be overwritten)
DEBUG=false # From file1.env
LOG_LEVEL=info # From file2.env
./target/release/envy-merge -d file1.env file2.env
This will print the merged output without saving it to a file.
./target/release/envy-merge -o merged.env file1.env file2.env
- If a file cannot be read, an error message is displayed, and the process exits with a non-zero code.
- Uses
anyhow
for robust error handling.
Feel free to open issues or submit pull requests to improve functionality!
This project is licensed under the MIT License.