53 [[nodiscard]] std::string
get_env(
const std::string &sVar)
const {
54 const auto pIter = this->m_mEnvVariables.find(sVar);
55 return pIter != this->m_mEnvVariables.end() ? pIter->second :
"";
64 [[nodiscard]] std::string
get_env_hop2(
const std::string &sVar)
const {
65 const auto pIter1 = this->m_mEnvVariables.find(sVar);
66 if (pIter1 == this->m_mEnvVariables.end())
return "";
67 const auto pIter2 = this->m_mEnvVariables.find(pIter1->second);
68 return pIter2 != this->m_mEnvVariables.end() ? pIter2->second :
"";
76 void set_env(std::string sVar, std::string sValue) {
77 this->m_mEnvVariables.insert_or_assign(std::move(sVar), std::move(sValue));
85 [[nodiscard]]
bool has_env(
const std::string &sVar)
const noexcept {
86 return this->m_mEnvVariables.contains(sVar);
94 return this->m_mEnvVariables.size();
101 [[nodiscard]]
const std::unordered_map<std::string, std::string, shell_hash> &
get_env() const noexcept {
102 return this->m_mEnvVariables;
107 std::unordered_map<std::string, std::string, shell_hash> m_mEnvVariables;
Represents an environment for shell commands.
Definition shell_env.h:42
shell_env()=default
Default constructor (empty environment).
std::size_t get_env_size() const noexcept
Gets the number of environment variables.
Definition shell_env.h:93
const std::unordered_map< std::string, std::string, shell_hash > & get_env() const noexcept
Retrieves all environment variables.
Definition shell_env.h:101
bool has_env(const std::string &sVar) const noexcept
Checks if an environment variable exists.
Definition shell_env.h:85
std::string get_env(const std::string &sVar) const
Retrieves the value of an environment variable.
Definition shell_env.h:53
void set_env(std::string sVar, std::string sValue)
Sets the value of an environment variable.
Definition shell_env.h:76
std::string get_env_hop2(const std::string &sVar) const
Retrieves the value of an environment variable, whose value is another variable (1-hop resolution).
Definition shell_env.h:64
BashSpark main namespace.
Definition command.h:39
Defines the bs::shell_hash functor implementing a 64-bit FNV-1a hash.