FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
ns_env Namespace Reference

Environment variable management utilities. More...

Enumerations

enum class  Replace { Y , N }
 

Functions

template<ns_concept::StringRepresentable T, ns_concept::StringRepresentable U>
void set (T &&name, U &&value, Replace replace)
 Sets an environment variable.
 
template<ns_string::static_string S = "E">
Value< std::string > get_expected (std::string_view name)
 Get the value of an environment variable.
 
bool exists (std::string_view name, std::string_view value)
 Checks if variable exists and equals value.
 
Value< std::string > expand (ns_concept::StringRepresentable auto &&var)
 Performs variable expansion analogous to a POSIX shell.
 
template<typename T = std::string>
Value< T > xdg_data_home () noexcept
 Returns or computes the value of XDG_DATA_HOME.
 
Value< fs::path > search_path (std::string const &query)
 Search the directories in the PATH variable for the given input file name.
 

Detailed Description

Environment variable management utilities.

Provides type-safe environment variable operations including get/set with default values, PATH searching for executables, variable expansion, and existence checking.

Enumeration Type Documentation

◆ Replace

enum class ns_env::Replace
strong

Definition at line 36 of file env.hpp.

Function Documentation

◆ exists()

bool ns_env::exists ( std::string_view name,
std::string_view value )
inline

Checks if variable exists and equals value.

Parameters
nameName of the variable
valueValue value of the variable
Returns
True if it exists and matches the expected value, or false otherwise

Definition at line 82 of file env.hpp.

Here is the caller graph for this function:

◆ expand()

Value< std::string > ns_env::expand ( ns_concept::StringRepresentable auto && var)
inline

Performs variable expansion analogous to a POSIX shell.

Template Parameters
autoType that is string representable (constrained by concept)
Parameters
varSource string to expand
Returns
Value<std::string> The expanded value or the respective error
Examples
/flatimage/src/filesystems/layers.hpp.

Definition at line 96 of file env.hpp.

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

◆ get_expected()

template<ns_string::static_string S = "E">
Value< std::string > ns_env::get_expected ( std::string_view name)
inline

Get the value of an environment variable.

Template Parameters
TThe output type of the function
Parameters
nameThe name of the variable
Returns
Value<std::string> The value of the variable or the respective error
Examples
/flatimage/src/filesystems/layers.hpp.

Definition at line 65 of file env.hpp.

Here is the caller graph for this function:

◆ search_path()

Value< fs::path > ns_env::search_path ( std::string const & query)
inlinenodiscard

Search the directories in the PATH variable for the given input file name.

Parameters
queryThe file name to search for in PATH directories
Returns
Value<fs::path> The path of the found file or the respective error

Definition at line 150 of file env.hpp.

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

◆ set()

void ns_env::set ( T && name,
U && value,
Replace replace )

Sets an environment variable.

Template Parameters
TStringRepresentable
UStringRepresentable
Parameters
nameVariable name
valueVariable value
replaceShould it be replace if it exists?

Definition at line 52 of file env.hpp.

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

◆ xdg_data_home()

template<typename T = std::string>
Value< T > ns_env::xdg_data_home ( )
inlinenoexcept

Returns or computes the value of XDG_DATA_HOME.

Template Parameters
TThe return type for the path (defaults to std::string, can be fs::path or other string-convertible types)
Returns
Value<T> The path to XDG_DATA_HOME or the respective error

Definition at line 135 of file env.hpp.

Here is the caller graph for this function: