MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / substitute_env_vars

Function substitute_env_vars

crates/opencode-config/src/loader.rs:397–404  ·  view source on GitHub ↗

Substitute `{env:VAR}` patterns with environment variable values. Works on the raw JSONC text before parsing.

(text: &str)

Source from the content-addressed store, hash-verified

395/// Substitute `{env:VAR}` patterns with environment variable values.
396/// Works on the raw JSONC text before parsing.
397fn substitute_env_vars(text: &str) -> String {
398 let re = regex::Regex::new(r"\{env:([^}]+)\}").unwrap();
399 re.replace_all(text, |caps: &regex::Captures| {
400 let var_name = &caps[1];
401 std::env::var(var_name).unwrap_or_default()
402 })
403 .to_string()
404}
405
406/// Resolve `{file:path}` patterns by reading file contents.
407/// Skips patterns on commented lines. Resolves relative paths from `base_dir`.

Callers 3

load_from_fileMethod · 0.85
test_substitute_env_varsFunction · 0.85

Calls 1

newFunction · 0.85

Tested by 2

test_substitute_env_varsFunction · 0.68