cenv
uses comments in .env
files to generate a schema used for checking the env files integrity. When working on a larger project, env files can change a lot and sometimes break your app if you have forgotten to add/edit/update certain fields. With cenv
you mimize this risk by having a source of truth that makes sure your env is set up correctly.
Copy and run the following command. cenv will be put in /usr/local/bin
.
curl -fsSL https://raw.githubusercontent.com/echo-webkom/cenv/refs/heads/main/install.sh | bash
Once installed, you can self-update with cenv-install
.
Add one or more of the following @tags
above a field:
public
: Marks the field as public. The value will be included in the schema. This is for required static values.required
: Marks the field as required. The field has to be present, and have a non-empty value.length [number]
: Requires a specified length for the fields value.format [format]
: Requires a specified format for the value. Uses gokenizer patterns.
NOT_SO_IMPORTANT=123
# @required
API_KEY=foo-bar-baz
# @length 8
OTHER_KEY=abcdefgh
# Stacking multiple tags
# @required
# @length 4
# @format {number}
PIN_CODE=1234
Create a schema file from your env:
# Creates a cenv.schema.json file
cenv update
Check you .env after fetching the latest changes
# Compares your env with the existing cenv.schema.json
cenv check
You can fix and outdated .env with the fix command. Note that this will overwrite the existing .env, but use the values that were there before, like secret API keys etc. This may not work correctly if the .env is formatted incorrectly.
cenv fix
To build the project, you need to have Go installed. Run the following command to build the project:
go build -o cenv cmd/cenv/main.go
If you want to overwrite the Version
variable in main.go
you have add the following flags:
go build -o cenv -ldflags "-X main.Version=<your-version>" cmd/cenv/main.go