envcheck compare

Compare multiple .env files to find missing or extra keys.

Usage

envcheck compare [OPTIONS] <BASE> <TARGET> [TARGETS...]

Arguments

  • <BASE> - Reference file (e.g., .env.example)
  • <TARGET> - File(s) to compare against base

Options

OptionDescription
-f, --format <FORMAT>Output format: text, json, github
-q, --quietSuppress output, use exit codes
--ignore <KEYS>Comma-separated keys to ignore

Exit Codes

CodeMeaning
0All keys present
1Missing keys found
2Extra keys found (info)

Examples

Compare example with production

envcheck compare .env.example .env.prod

Output:

W004: Missing key in .env.prod: DATABASE_URL
W004: Missing key in .env.prod: REDIS_URL
I001: Extra key in .env.prod: PRODUCTION_SECRET

Compare multiple environments

envcheck compare .env.example .env.staging .env.prod

JSON output

envcheck compare .env.example .env.prod --format=json

Ignore specific keys

envcheck compare .env.example .env.prod --ignore=FEATURE_FLAG_X

Use Cases

Pre-deployment validation

#!/bin/bash
if envcheck compare .env.example .env.prod --quiet; then
    echo "All required keys present"
    kubectl apply -f deployment.yaml
else
    echo "Missing keys in production!"
    exit 1
fi

CI/CD pipeline

- name: Validate production environment
  run: envcheck compare .env.example .env.prod --format=github

Detected Issues

CodeRuleSeverityDescription
W004Missing KeyWarningKey present in base but missing in target
I001Extra KeyInfoKey present in target but not in base

See Also