yaml-env-cli
v0.0.2
Published
CLI to help you set environment variables based on your YAML file
Downloads
18
Readme
YAML-env-CLI
A CLI that does only one thing: outputs the contents of a YAML
file (.yml
or .yaml
) as a string (so as to help you load each key/value pair as environment variables).
Install
npm install -g yaml-env-cli
How to use
For example, you have a file staging.yaml
[^1]:
ENVIRONMENT: "staging"
API_URL: "https://lol.hi"
API_KEY: "69sike420"
Running yec staging.yaml
will output the string:
API_KEY=69sike420 API_URL=https://lol.hi ENVIRONMENT=staging
This is useful because you can instead run[^2]:
export `yec staging.yaml`
Now all the secrets in staging.yaml
will be available in your terminal as environment variables.
So if you have a main.go
script that requires certain variables, you can run:
export `yec staging.yaml` && go run main.go
Tip
To see what environment variables are set, run printenv
(this is just a regular shell command).
Developing
Running npm start
reads the sample.yaml
, exports each key/value pair as environment variables, and runs test.js
which will print the three[^3] set variables.
Note: npm start
will not update the environment variables except for the execution of test.js
Adjust the script to your liking by editing index.js
and then install your custom version of yec
command with npm run global
Motivation
Launching Cloud Functions to GCP is easy with --env-vars-file=production.yml
but when you try to use the Functions Framework you now have to figure out a way to get those environment variables loaded. Perhaps you use a shell script which duplicates the contents of the .yml
file, but it's annoying.
[^1]: Note that the CLI expects a flat file with no nesting [^2]: Note this CLI might not work on Windows [^3]: Note that the three keys are hardcoded for convenience