NOTE: This product has been deprecated and archived. Use zenv instead.
CLI Environment Variable Controller in Go
$ cat setting.env
DB_NAME = AWESOME_DATABASE
$ cat sample.py
import os
print("my database is {0}".format(os.environ["DB_NAME"]))
$ altenv -e setting.env python sample.py
my database is AWESOME_DATABASE
$ go get -u github.com/m-mizutani/altenv
Sample yourfile.env
# Comment out is available
KEY1 = ABC
KEY2 = BCD
$ altenv -e yourfile.env <command> [arg1, [arg2, [...]]]
Sample yourfile.json
. JSON file must be map format with pairs of key(string) and value(string).
{
"KEY1": "ABC",
"KEY2": "BCD"
}
$ altenv -j yourfile.json <command> [arg1, [arg2, [...]]]
altenv
provides dryrun feature to confirm conputed environment variables.
$ altenv -i yourfile.env -r dryrun
KEY1=ABC
KEY2=BCD
If you want to hide input value, you can use --prompt
option for no-echo input.
$ altenv --prompt TOKEN ./deploy.sh
Enter TOKEN value:
altenv
can saves environment variable to macOS Keychain and loads saved variable from Keychain. This feature is appropriate to manage secret values e.g. credential key, token, etc. altenv
can have multiple namespaces. This is inspired by envchain.
If you already have plain text credential, you can use stdin option, -i env
. -i
option required input format and env
means KEY1=ABC
style.
$ cat credentials.env | altenv -r update-keychain -w your_namespace -i env
Or you can set secrets with --prompt
option. Prompt input works with no echo, then you can put secrets more securely.
$ altenv -r update-keychain -w your_namespace --prompt AWS_SECRET_ACCESS_KEY
Enter AWS_SECRET_ACCESS_KEY value:
After that, you can import saved secret values by -k <namespace>
option.
$ altenv -k your_namespace aws s3 ls
altenv imports config file when invoked. $HOME/.altenv
is default config path (ignore if not exists) and config path can be specified -c
option. Config file can be written in toml format.
There are 3 types of section in configuration file.
global
: The section's configurations are always imported.profile.xxx
: Profile can be switched by CLI option-p
.profile.xxx
is imported when-p xxx
is given in CLI.profile.default
: The section is imported by default. If you specifiy profile name other thandefault
, this section is not imported.
workdir.xxx
: WorkDir section is enabled by your current working directory. Directory path can be specified bydirpath
(See Configuration fields part).dirpath
works as directory path prefix. If multipledirpath
are matcehd with current working directory, all matched configurations are imported. NOTE:xxx
is just label in WorkDir section.
envfile
(array of string): Specify envfile foramt file(s). (multiple lines withKEY1=ABC
style)jsonfile
(array of string): Specify json format file(S). Only map format of string key and value is acceptable.define
(array of string): Specify environment variable(s) directly withKEY1=ABC
style.keychain
(array of string): Specify namespace(s) for environment variables stored in Keychain. See Use Keychain part.overwrite
(string, [deny
|warn
|allow
]): Specify Overwrite policy. Default isdeny
andaltenv
abort program when environment variable key conflict.warn
is only output warning message.allow
allows overwrite when collision.keychainServicePrefix
: Specify prefix of service name of Keychain. Default isaltenv.
dirpath
(string): Required in onlyworkdir
section. Specify prefix of working directoy.
Example of $HOME/.altenv
is following.
[global]
define = ["ALWAYS=ENABLED"]
[profile.default]
define = ["PROFILE_IS=DEFAULT"]
[profile.mytest]
define = ["PRFILE_IS=MY_TEST"]
[workdir.proj1]
dirpath = "/Users/mizutani/works/proj1"
define = ["DBNAME=proj1"]
[workdir.proj2]
dirpath = "/Users/mizutani/works/proj2"
define = ["DBNAME=proj2"]
Run with the configuration.
$ cd /Users/mizutani
$ altenv -r dryrun
ALWAYS=ENABLED
PROFILE_IS=DEFAULT
$ cd /Users/mizutani/works/proj1
$ altenv -r dryrun
ALWAYS=ENABLED
DBNAME=proj1
PROFILE_IS=DEFAULT
$ altenv -r dryrun -p mytest
ALWAYS=ENABLED
DBNAME=proj1
PRFILE_IS=MY_TEST
- MIT License
- Author: [email protected]