Watch Mode
Watch mode automatically re-validates your .env files whenever they change. Perfect for development workflows.
Basic Usage
bash
envguard validate --watchEnvGuard will:
- Run an initial validation
- Watch
.envfiles and the schema for changes - Re-validate after a debounce period
- Print results to the terminal
With Custom Options
bash
envguard validate --watch -s envguard.yaml -e .env -e .env.local --strictWatch Command
The dedicated watch command provides additional control:
bash
envguard watch -e .env -s envguard.yamlOptions
| Flag | Description |
|---|---|
--debounce | Debounce duration (default: 300ms) |
--command | Run a shell command after each validation |
--clear | Clear the terminal before each run |
--quiet | Only show errors |
Running Commands on Change
Trigger your test suite or application restart on validation:
bash
envguard watch --command "npm test"bash
envguard watch --clear --command "go run ./cmd/app"Output Formats
Watch mode supports all standard output formats:
bash
# JSON output (useful for editor integration)
envguard watch -f json
# GitHub Actions format
envguard watch -f githubHow It Works
EnvGuard uses fsnotify for efficient filesystem watching. Changes are debounced to avoid excessive re-validation during rapid file edits.
The watcher handles:
- File writes and renames
- File creation (for new
.envfiles) - Directory watching for monorepo setups
- Graceful shutdown on
Ctrl+C