Hwaro::Utils::EnvSubstitutor
Constants
PATTERN = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*(?:\{[^}]*\}[^}]*)*))?\}|\$([A-Za-z_][A-Za-z0-9_]*)\b/
Combined regex: matches ${VAR}, ${VAR:-default}, or bare $VAR in a single pass. This avoids double-substitution where a replaced value could contain $-patterns.
Group 1: braced var name (from ${VAR} or ${VAR:-default}) Group 2: default value (from ${VAR:-default}, nil when absent) Group 3: bare var name (from $VAR)
NOTE: Nested ${...} in default values is not supported.
Default values may contain } as long as it's inside balanced braces.
Class methods
substitute(input : String) : Tuple(String, Array(String))
Substitute environment variables in the given string. Returns the substituted string and a list of missing variable names.
Semantics (aligned with POSIX shell):
- ${VAR} → value if set (even empty), original text + warning if unset
- ${VAR:-default} → value if set AND non-empty, otherwise default
- $VAR → value if set (even empty), original text + warning if unset
substitute_with_warnings(input : String, source : String = "config") : String
Substitute and log warnings for missing variables