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_
 

Detailed Description

Definition at line 37 of file EnvExpander.h.

Member Enumeration Documentation

◆ Operation

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

Definition at line 79 of file EnvExpander.h.

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.

Definition at line 109 of file EnvExpander.cpp.

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.

Definition at line 114 of file EnvExpander.cpp.

+ Here is the call graph for this function:

◆ applyOperation()

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

Definition at line 309 of file EnvExpander.cpp.

+ Here is the caller graph for this function:

◆ 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).

Definition at line 150 of file EnvExpander.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expandVariables()

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

Definition at line 271 of file EnvExpander.cpp.

+ Here is the caller graph for this function:

◆ splitAssignments()

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

Definition at line 231 of file EnvExpander.cpp.

+ Here is the caller graph for this function:

◆ splitOperation()

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

Definition at line 239 of file EnvExpander.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ env_

boost::process::environment env_

Definition at line 86 of file EnvExpander.h.


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