This quickstart sets up the smallest useful withenv project: a .withenv.yml alias file and a devenv.yml file containing environment variables. After that, prefix commands with we and they run with your project environment.
brew install ionrock/tap/we
# or
go install github.com/ionrock/we/cmd/we@latestVerify the CLI is available:
we --versionCreate a file named devenv.yml in your project:
---
APP_ENV: development
LOG_LEVEL: debug
DATABASE_URL: postgres://localhost/myapp
PORT: "8080"These values will be available to commands launched through we.
Create a .withenv.yml alias file next to devenv.yml:
---
- file: devenv.ymlWhen you run we anywhere in this directory tree, it searches upward for .withenv.yml and loads it automatically.
Run commands exactly as you normally would, but prefix them with we:
we printenv APP_ENV
# development
we go test ./...
we npm run dev
we ./my-appYour current shell is unchanged. The variables are applied only to the child command.
With no command, we runs env:
weTo see only variables loaded by withenv sources, use --clean:
we --cleanAdd --debug / -D when you want to see how we discovers and applies files:
we --debug --clean
we -D --clean printenv APP_ENVUse --envvar / -E for one-off overrides:
we -E LOG_LEVEL=trace ./my-appCLI flags are applied after .withenv.yml, so the override wins.
Like direnv, we auto-loads .envrc, not .env directly. If you already have a dotenv-style .env, create this .envrc:
dotenvThat loads .env from the same directory. You can also name a file explicitly:
dotenv .env.localYou can layer files by adding entries to .withenv.yml:
---
- file: devenv.yml
- file: local.ymlLater entries override earlier entries. This is useful for local machine-specific values that should not be shared.
- Use Reference for every CLI flag and option.
- Use Advanced usage for scripts, templates, and
--agent.