cenv uses a TOML schema file (cenv.schema.toml) to validate and manage your .env files. 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 minimize this risk by having a source of truth that makes sure your env is set up correctly.
curl -fsSL https://raw.githubusercontent.com/echo-webkom/cenv/refs/heads/main/install.sh | bashcenv will be installed to your $HOME/.local/bin. Make sure that the it is added to your $PATH.
Make sure you have Rust installed, then run:
cargo install --path .Create a cenv.schema.toml file that defines your environment variables:
[[entries]]
key = "DATABASE_URL"
required = true
kind = "Url"
[[entries]]
key = "API_PORT"
hint = "Port number as an integer"
required = true
default = "3000"
kind = { Integer = { min = 1, max = 65535 } }
[[entries]]
key = "LOG_LEVEL"
required = false
default = "info"
legal_values = ["debug", "info", "warn", "error"]Each entry supports the following fields:
key: The environment variable name (required)hint: Human-readable description of the fieldrequired: Iftrue, the field must be present and non-emptydefault: Default value used when generating the.envfilelegal_values: List of allowed values for the fieldrequired_length: Exact required length for the valueregex_match: Regex pattern the value must matchkind: Type validation - one of:StringInteger(with optionalmin/max)Float(with optionalmin/max)BoolUrlEmailIpAddressPath
Check your .env against the schema:
# Validates .env against cenv.schema.toml
cenv checkGenerate or update your .env file from the schema:
# Creates .env or fills in missing values from schema defaults
cenv fixThe fix command preserves any existing values in your .env file (like API keys) while adding missing fields with their default values from the schema.
Both commands support custom paths:
cenv check --schema my-schema.toml --env .env.local
cenv fix --schema my-schema.toml --env .env.local