Expand description
${VAR} substitution for configuration values.
Config files are checked into repos and shared; secrets are not. So a value may name an environment variable instead of carrying one:
[provider]
api_key = "${OPENAI_API_KEY}"Two forms, and both are deliberately small:
${NAME}— the value ofNAME; an unset variable is an error that names the key, never an empty string. A provider that silently gets""for its key fails much later and much less clearly than a config that refuses to load.${NAME:-fallback}— the value, orfallbackwhenNAMEis unset or empty (the shell’s meaning of:-).
$$ escapes a literal $, so $${X} stays ${X}. There is no recursion — the result
of a substitution is never itself substituted — and no command substitution. Anything
else starting with $ is left alone, which keeps prices, $HOME-looking prose in a
prompt, and regex fragments working.
Substitution happens on parsed TOML values, not on the file text: a comment that
mentions ${HOME} is documentation, not a reference, and must not be able to break a
config or leak a value into the wrong place.
Functions§
- in_
value - Substitute
${...}in every string insidevalue, in place. - substitute
- Substitute in one string.
pathis the config key, for error messages.