env command
keel env <subcommand>Three subcommands:
keel env sync # generate/update .env.examplekeel env generate # generate .env (only missing keys)keel env check # validate required varsNo standalone flags on keel env itself. Each subcommand takes no flags.
Source of truth for env vars
Section titled “Source of truth for env vars”keel env reads variable declarations from, in order of priority:
application.properties— if it exists (new runtime config contract)keel.toml—[[env]]entries (legacy)
keel env sync
Section titled “keel env sync”keel env syncGenerates or updates .env.example from declared variables.
${KEY}placeholder → appendsKEY=to.env.example${KEY:default}placeholder → appendsKEY=default- Sensitive keys with no default → placeholder value:
your-secret-here - Keys already present in
.env.exampleare not overwritten (idempotent) - Manual entries in
.env.examplethat are not declared inapplication.propertiesare preserved
Output
Section titled “Output” ✓ added 3 key(s) to .env.exampleor:
✓ .env.example is up to dateExample
Section titled “Example”Given application.properties:
server.port=${PORT:8080}database.dsn=${DB_DSN}jwt.secret=${JWT_SECRET}Running keel env sync appends to .env.example:
PORT=8080DB_DSN=JWT_SECRET=your-secret-herekeel env generate
Section titled “keel env generate”keel env generateGenerates or updates .env from declared variables. Only adds missing keys.
- Required vars (no default) →
KEY=(empty, must be filled) - Optional vars (with default) →
# KEY=default(commented out) - Keys already present in
.env(active or commented) are not duplicated - Existing
.envcontent is never overwritten
Output
Section titled “Output” ✓ added 2 key(s) to .envor:
✓ .env already has all declared keysTypical workflow
Section titled “Typical workflow”git pullkeel env generate # adds keys declared by teammates# fill in empty valueskeel run devkeel env check
Section titled “keel env check”keel env checkValidates that required variables are set. Reads from .env first, then OS environment.
Output symbols
Section titled “Output symbols”| Symbol | Meaning |
|---|---|
✓ | Variable is set |
✗ | Required variable is missing (exits non-zero) |
⚠ | Optional variable is not set |
Example output
Section titled “Example output” ✓ PORT is set ✓ DB_DSN is set (via OS env) ✗ JWT_SECRET is missing ⚠ REDIS_URL is not set (optional)The command exits with non-zero if any required variable is missing.
Relationship with keel doctor
Section titled “Relationship with keel doctor”keel doctor also checks required env vars, but keel env check is narrower and faster — useful in CI pipelines to validate the environment before deploying.
# Minimal CI env validationkeel env check || exit 1Common errors
Section titled “Common errors”reading application.properties: ...reading keel.toml: ...opening .env.example: ...missing required environment variables(exit code fromkeel env check)
Best practices
Section titled “Best practices”- Commit
.env.example— it’s safe (no real values). - Never commit
.env— add it to.gitignore. - Run
keel env syncafter updatingapplication.propertiesto keep.env.examplecurrent. - Run
keel env checkin CI before deploying.