Environment#
Environment variable access and manipulation functions and facilities.
Info
To use declarations from this page, include the <essence/environment.hpp> header.
-
std::string env::get(std::string_view key, std::string_view fallback = "")#
Get the value of an environment variable by name, with a fallback value when the variable is not set.
-
bool env::set(std::string_view key, std::string_view value, bool clobber = false)#
Set the environment variable
keytovalue. If clobber istrue, overwrite an existing value.
-
bool env::unset(std::string_view key)#
Unset an environment variable by name. Returns true upon success, false otherwise.
-
std::vector<std::string> env::vec(char *const *envs = environ)#
Construct a
std::vectorfrom the a null-terminated environment array. Each member of the result is the entire pair, including the=.Uses the value of environ unless explicitly passed a value.
-
std::unordered_map<std::string, std::string> env::map(char *const *envs = environ)#
Construct a std::unordered_map from the null-terminated environment array.
Uses the value of environ unless explicitly passed a value.
-
detail::environment_t environment#
Global proxy object instance for convenient but safe environment access and manipulation. Provides null-safe access to the POSIX
getenv,setenv,unsetenvfamily of functions.detail::environment_t is an implementation detail, all interaction should be go through this object.
Usage
std::string path = environment["PATH"]; std::string shell = environment.get("SHELL", "/bin/sh"); environment.set("SOME_THING", "foo"); environment.set("SOME_THING", "bar", /*clobber=*/ true); environment.unset("SOME_THING");
-
class detail::environment_t#
-
std::string operator[](std::string_view key)#
Get the value of
keyin the environment, or an empty string if unset.
-
std::string get(std::string_view key, std::string_view fallback = "")#
Get the value of
keyin the environment, or the value offallbackif unset.
-
void set(std::string_view key, std::string_view value, bool clobber = false)#
Set the environment variable
keytovalue, overwriting an existing value ifclobberis true.
-
void unset(std::string_view key)#
Unset the environment variable
key.
-
std::string operator[](std::string_view key)#