Documentation
¶
Overview ¶
Package envfile loads .env-style files, prompts interactively for missing required values, and writes them back. Designed for per-tool config that each binary keeps next to itself (e.g. bin/projects/<name>/.env).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load parses a .env file. Missing files return an empty map and no error. Lines are KEY=VALUE; lines starting with `#` and blank lines are ignored. Surrounding double or single quotes are stripped from values.
func MigrateOnce ¶
func MigrateOnce(currentPath, legacyPath string)
MigrateOnce copies legacyPath → currentPath on first run after the canonical location moves (e.g. when `.env` shifts under XDG). Best-effort: silently does nothing if currentPath already exists, legacyPath is missing, or any I/O step fails — the user will be prompted to refill the file through Resolve like a fresh install. On a successful copy a single-line notice is written to stderr so the move isn't invisible. The legacy file is left in place so downgrading to an older binary still finds its config.
func Resolve ¶
Resolve fetches values for every Field in priority order:
- existing entry in path
- process environment ($KEY)
- Default (silent fallback)
- interactive prompt (Required only) — saved back to path
All resolved values are returned. Stdin must be a TTY when prompting is needed; otherwise an error is returned listing the missing keys.
Types ¶
type Field ¶
type Field struct {
Key string
Prompt string // shown to user when interactive
Description string // short help shown above the prompt
Default string // used silently if no value found anywhere
Required bool // missing required → prompt (or error if non-TTY)
Validator func(string) error // returns error if value is invalid
}
Field describes a single environment variable a tool needs.