Crates.io | envi |
lib.rs | envi |
version | 0.1.0 |
source | src |
created_at | 2022-03-16 11:36:35.135484 |
updated_at | 2022-03-16 11:36:35.135484 |
description | A simple CLI tool to manage environment variables for multiple environments |
homepage | https://github.com/zklinger/envi |
repository | https://github.com/zklinger/envi |
max_upload_size | |
id | 551100 |
size | 59,955 |
A simple CLI tool to manage environment variables for multiple environments.
The idea is to define common and environment specific environment variables in a configuration file and then use envi
to generate a list of environment variables from the config file that is relevant for a given environment.
Let's assume we have two environments dev
and qa
for which we want to have some environment variables set.
Let's create a configuration file for envi
to use. By default, envi
will look for a file named .envi.toml
in the current working directory. The config file to use can be also defined in the ENVI_FILE
environment variable or using the -i
command line option.
File type | File extension |
---|---|
TOML | .toml |
YAML | .yml or .yaml |
JSON | .json |
The configuration file consists of a list of top level key value pairs representing environment variables that are common in all environments and one or many tables for each environment. These tables contain key value pairs specific to that particular environment (potentially overwiriting top level ones).
For example, our .envi.toml
could look like something like this:
# file: .envi.toml
# some common env variables
FOO = "mother_of_all_foos"
BAR = "mother_of_all_bars"
BAZ = 9999
# "dev" specific env variables
[dev]
FOO = "dev_foo"
BAR = "dev_bar"
QUX = "quxxxx"
# "qa" specific env variables
[qa]
FOO = "qa_foo"
or the same content in a YAML
format:
# file: .envi.yaml
# some common env variables
FOO: mother_of_all_foos
BAR: mother_of_all_bars
BAZ: 9999
# "dev" specific env variables
dev:
FOO: dev_foo
BAR: dev_bar
QUX: quxxxx
# "qa" specific env variables
qa:
FOO: qa_foo
or the same content in a JSON
format:
{
"FOO": "mother_of_all_foos",
"BAR": "mother_of_all_bars",
"BAZ": 9999,
"dev": {
"FOO": "dev_foo",
"BAR": "dev_bar",
"QUX": "quxxxx"
},
"qa": {
"FOO": "qa_foo"
}
}
The keys
subcommand lists all configured environments from the config file.
% envi keys
dev
qa
The show
subcommand outputs all environment variables for a given key.
% envi show dev
BAR=dev_bar
BAZ=9999
FOO=dev_foo
QUX=quxxxx
% envi show qa
BAR=mother_of_all_bars
BAZ=9999
FOO=qa_foo
You can easily put these values into a file, for example into .env
by either piping the output:
envi show qa >.env
or using the -o
option to write it to a file
envi show qa -o .env
The diff
subcommand allows you to compare configured environment variables between two environments.
% envi diff dev qa
--- dev
+++ qa
- BAR=dev_bar
+ BAR=mother_of_all_bars
- FOO=dev_foo
+ FOO=qa_foo
- QUX=quxxxx
The ediff
subcommand allows you to compare current shell evironment variables with a the environment variables configured for a given key.
% FOO=foo BAR=bar BAZ=baz QUX=xxx envi ediff dev
--- env
+++ dev
- BAR=bar
+ BAR=dev_bar
- BAZ=baz
+ BAZ=9999
- FOO=foo
+ FOO=dev_foo
- QUX=xxx
+ QUX=quxxxx