Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
vulcan::io::YamlEnv Class Reference

Environment variable expansion utilities. More...

#include <YamlEnv.hpp>

Static Public Member Functions

static std::string Expand (const std::string &value, bool strict=true)
 Expand environment variables in a string.
static bool ContainsEnvVars (const std::string &value)
 Check if string contains environment variable references.
static YamlNode ExpandAll (const YamlNode &node)
 Recursively expand all string values in a YAML tree.
static YamlNode LoadFileWithEnv (const std::string &path)
 Load YAML file with environment variable expansion.
static YamlNode LoadWithIncludesAndEnv (const std::string &path)
 Load with includes AND environment expansion.
static YamlNode LoadFromEnvPath (const std::string &path_with_vars)
 Expand envvars in path, then load the file.
static std::optional< std::string > GetEnv (const std::string &name)
 Get environment variable value.
static std::string GetEnv (const std::string &name, const std::string &default_value)
 Get environment variable with default.

Detailed Description

Environment variable expansion utilities.

Member Function Documentation

◆ ContainsEnvVars()

bool vulcan::io::YamlEnv::ContainsEnvVars ( const std::string & value)
inlinestatic

Check if string contains environment variable references.

◆ Expand()

std::string vulcan::io::YamlEnv::Expand ( const std::string & value,
bool strict = true )
inlinestatic

Expand environment variables in a string.

Parameters
valueString potentially containing ${VAR} or ${VAR:default}
strictIf true, throws on undefined variables without defaults
Returns
Expanded string
Exceptions
EnvVarErrorif strict=true and required variable is undefined

◆ ExpandAll()

YamlNode vulcan::io::YamlEnv::ExpandAll ( const YamlNode & node)
inlinestatic

Recursively expand all string values in a YAML tree.

Parameters
nodeRoot node to expand
Returns
New YamlNode with expanded values

◆ GetEnv() [1/2]

std::optional< std::string > vulcan::io::YamlEnv::GetEnv ( const std::string & name)
inlinestatic

Get environment variable value.

Parameters
nameVariable name (without $)
Returns
Value if defined, nullopt otherwise

◆ GetEnv() [2/2]

std::string vulcan::io::YamlEnv::GetEnv ( const std::string & name,
const std::string & default_value )
inlinestatic

Get environment variable with default.

◆ LoadFileWithEnv()

YamlNode vulcan::io::YamlEnv::LoadFileWithEnv ( const std::string & path)
inlinestatic

Load YAML file with environment variable expansion.

Order of operations:

  1. Load file
  2. Expand envvars in all string values

◆ LoadFromEnvPath()

YamlNode vulcan::io::YamlEnv::LoadFromEnvPath ( const std::string & path_with_vars)
inlinestatic

Expand envvars in path, then load the file.

◆ LoadWithIncludesAndEnv()

YamlNode vulcan::io::YamlEnv::LoadWithIncludesAndEnv ( const std::string & path)
inlinestatic

Load with includes AND environment expansion.

Order of operations:

  1. Expand envvars in the path itself
  2. Resolve !include directives (with envvar expansion in paths)
  3. Expand envvars in all string values

The documentation for this class was generated from the following file: