EnvExpander Class Reference

#include <ArmarXCore/core/system/EnvExpander.h>

Public Types

enum class  Operation : std::uint8_t { Replace , Append , Prepend }
 

Public Member Functions

void apply (const std::string &input, bool expandExisting=true)
 Parse and apply the comma-separated assignment list to the internal environment env_ and to the process environment via setenv.
 
void applyOperation (const std::string &name, Operation op, const std::string &val)
 
 EnvExpander ()
 Construct an EnvExpander initialized with the current process environment.
 

Static Public Member Functions

static std::string expand (const std::string &input)
 Return the expanded form of the comma-separated assignment list without modifying the process environment.
 
static std::string expandVariables (const std::string &value)
 
static std::vector< std::string > splitAssignments (const std::string &input)
 
static std::tuple< std::string, Operation, std::string > splitOperation (const std::string &assignment)
 

Public Attributes

boost::process::environment env_
 

Member Enumeration Documentation

◆ Operation

enum class Operation : std::uint8_t
strong
Enumerator
Replace 
Append 
Prepend 

Constructor & Destructor Documentation

◆ EnvExpander()

Construct an EnvExpander initialized with the current process environment.

The instance keeps a working copy of the environment (stored in env_) which apply() will update when assignments are applied. This allows expansions to optionally see earlier changes.

Member Function Documentation

◆ apply()

void apply ( const std::string & input,
bool expandExisting = true )

Parse and apply the comma-separated assignment list to the internal environment env_ and to the process environment via setenv.

The input format is a comma-separated list of assignments. Each assignment may be a replace (NAME=val), append (NAME+=val) or prepend (NAME=+val). Whitespace around entries is ignored. Values may include environment variable references (e.g. $HOME or ${HOME}), which will be expanded before applying the assignment.

Current implementation notes: apply uses expand to expand the RHS values and then applies the parsed operations. The working copy env_ is updated so later calls can observe previous changes.

◆ applyOperation()

void applyOperation ( const std::string & name,
Operation op,
const std::string & val )

◆ expand()

std::string expand ( const std::string & input)
static

Return the expanded form of the comma-separated assignment list without modifying the process environment.

This mirrors the expansions performed by apply.

Special behavior: append and prepend operations are returned as explicit replacement assignments combining the existing environment value and the expanded RHS. For example, if the current value of PATH is "/usr/bin" and the input contains "PATH+=/opt/bin", this method returns "PATH=/usr/bin:/opt/bin" (or "PATH=/opt/bin" if PATH was not previously set).

◆ expandVariables()

std::string expandVariables ( const std::string & value)
static

◆ splitAssignments()

std::vector< std::string > splitAssignments ( const std::string & input)
static

◆ splitOperation()

std::tuple< std::string, EnvExpander::Operation, std::string > splitOperation ( const std::string & assignment)
static

Member Data Documentation

◆ env_

boost::process::environment env_

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