envi

Crates.ioenvi
lib.rsenvi
version0.1.0
sourcesrc
created_at2022-03-16 11:36:35.135484
updated_at2022-03-16 11:36:35.135484
descriptionA simple CLI tool to manage environment variables for multiple environments
homepagehttps://github.com/zklinger/envi
repositoryhttps://github.com/zklinger/envi
max_upload_size
id551100
size59,955
Zoltan Klinger (zklinger)

documentation

README

License: MIT Build

envi

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.

Usage

Let's assume we have two environments dev and qa for which we want to have some environment variables set.

The config file

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.

Supported file formats

File type File extension
TOML .toml
YAML .yml or .yaml
JSON .json

Config file layout

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"
  }
}

List all available keys

The keys subcommand lists all configured environments from the config file.

% envi keys
dev
qa

Show environment variables for a given key

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

Compare environments

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

Compare current shell environment variables with a given environment

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
Commit count: 1

cargo fmt