Documentation
¶
Overview ¶
Package dotenv loads KEY=VALUE pairs from .env files into a map. It is deliberately minimal: yottacode uses .env exclusively for API keys, so the parser only needs to cover what dev tooling already produces — quoted values, comments, optional `export` prefix.
The format follows the de-facto subset shared across Docker, direnv, and godotenv:
# comment line KEY=value KEY="quoted value" # double quotes preserve as-is KEY='single quoted' # single quotes preserve as-is, no escapes export KEY=value # leading export is silently dropped KEY=value # trailing comment after a space
Multi-line values, escape sequences inside double quotes, and variable interpolation are NOT supported. The moment we need any of those we'll reach for github.com/joho/godotenv; today we don't.
Index ¶
- func Apply(m map[string]string) []string
- func DefaultPath() (string, error)
- func DeleteKey(path, name string) (bool, error)
- func Load(path string) (map[string]string, error)
- func LoadAndApply(paths ...string) ([]string, error)
- func LoadChain(paths ...string) (map[string]string, error)
- func Save(path string, kv map[string]string) error
- func SetKey(path, name, value string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply populates os.Environ with values from m, but never overrides a variable that's already set. The OS environment wins so CI/CD secrets take precedence over a checked-in .env. Returns the list of keys actually applied (for diagnostics).
func DefaultPath ¶
DefaultPath returns ~/.yottacode/.env — the home-scoped, yottacode- managed env file where API keys land. Save/SetKey/DeleteKey use it as their default; callers needing a per-repo .env pass a path directly.
func DeleteKey ¶
DeleteKey removes name from path and writes back. Returns (true, nil) when the key was present and the file was rewritten, (false, nil) when the file or key is missing (a no-op, not an error — the caller's typical question is "is the key gone?" and the answer is yes either way), or (false, err) on a real I/O failure. Used by `provider remove` to clean up the matching API key from ~/.yottacode/.env so removing a profile actually removes its credential.
func Load ¶
Load parses the file at path and returns its KEY=VALUE pairs. A missing file is not an error — the caller can chain Load calls and treat absent files as empty layers.
func LoadAndApply ¶
LoadAndApply is the common-case helper: load a chain of files and merge into the live environment without overriding existing values.
func LoadChain ¶
LoadChain loads multiple .env files in order. Later files override earlier ones. Missing files are skipped silently. Callers pass the chain in "lowest precedence first" order — typically (user-global, project-local).
func Save ¶
Save writes kv atomically to path at mode 0600. Keys are sorted so diffs read stably across writes; values are double-quoted so they survive any whitespace/special chars. A "managed" header tells users this file is rewritten by yottacode commands. Parent dirs are created at 0700 if missing. Empty kv writes just the header (a blank but valid yottacode-managed file).
Types ¶
This section is empty.