BashSpark
Loading...
Searching...
No Matches
bs::command_getenv Class Reference

Retrieves the value of an environment variable. More...

#include <command_env.h>

Inheritance diagram for bs::command_getenv:
Collaboration diagram for bs::command_getenv:

Public Member Functions

 command_getenv ()
 Constructs command.
 
shell_status run (const std::span< const std::string > &vArgs, shell_session &oSession) const override
 Prints the env variable value on stdout. If the env variable does not exist, does nothing.
 
virtual void msg_error_param_number (std::ostream &oStdErr, std::size_t nArgs) const
 Print an error if the wrong number of arguments is provided.
 
virtual void msg_error_variable_name (std::ostream &oStdErr, const std::string &sVariableName) const
 Print an error if variable name is invalid.
 
- Public Member Functions inherited from bs::command
 command (std::string sName)
 Construct a command with a given name.
 
virtual ~command ()=default
 Virtual destructor.
 
std::string get_name () const
 Get the command name (copy).
 
const std::string & get_name_ref () const noexcept
 Get the command name (reference).
 

Detailed Description

Retrieves the value of an environment variable.

Syntax: getenv variable

Member Function Documentation

◆ msg_error_param_number()

void bs::command_getenv::msg_error_param_number ( std::ostream &  oStdErr,
std::size_t  nArgs 
) const
virtual

Print an error if the wrong number of arguments is provided.

Parameters
oStdErrStream to print error message.
nArgsNumber of provided arguments.

◆ msg_error_variable_name()

void bs::command_getenv::msg_error_variable_name ( std::ostream &  oStdErr,
const std::string &  sVariableName 
) const
virtual

Print an error if variable name is invalid.

Parameters
oStdErrStream to print error message.
sVariableNameVariable name provided.

◆ run()

shell_status bs::command_getenv::run ( const std::span< const std::string > &  vArgs,
shell_session oSession 
) const
overridevirtual

Prints the env variable value on stdout. If the env variable does not exist, does nothing.

If the parameter number does not match 1 then method msg_error_param_number is called. If the variable names is invalid then method msg_error_variable_name is called.

Parameters
vArgsArguments for the command.
oSessionThe shell session context.
Returns
Status of command execution.

Implements bs::command.


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