BashSpark
Loading...
Searching...
No Matches
command_env.h
Go to the documentation of this file.
1
27#pragma once
28
29#include "BashSpark/command.h"
30
31namespace bs {
38 class command_getenv : public command {
39 public:
44 : command("getenv") {
45 }
46
58 [[nodiscard]] shell_status run(
59 const std::span<const std::string> &vArgs,
60 shell_session &oSession
61 ) const override;
62
63 public:
69 virtual void msg_error_param_number(std::ostream &oStdErr, std::size_t nArgs) const;
70
76 virtual void msg_error_variable_name(std::ostream &oStdErr, const std::string &sVariableName) const;
77 };
78
85 class command_setenv : public command {
86 public:
91 : command("setenv") {
92 }
93
105 [[nodiscard]] shell_status run(
106 const std::span<const std::string> &vArgs,
107 shell_session &oSession
108 ) const override;
109
110 public:
116 virtual void msg_error_param_number(std::ostream &oStdErr, std::size_t nArgs) const;
117
123 virtual void msg_error_variable_name(std::ostream &oStdErr, const std::string &sVariableName) const;
124 };
125}
Retrieves the value of an environment variable.
Definition command_env.h:38
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.
Definition command_env.cpp:33
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.
Definition command_env.cpp:53
command_getenv()
Constructs command.
Definition command_env.h:43
virtual void msg_error_variable_name(std::ostream &oStdErr, const std::string &sVariableName) const
Print an error if variable name is invalid.
Definition command_env.cpp:57
Sets the value of an environment variable.
Definition command_env.h:85
command_setenv()
Constructs command.
Definition command_env.h:90
shell_status run(const std::span< const std::string > &vArgs, shell_session &oSession) const override
Sets the env variable value. If the env variable does not exist, creates it.
Definition command_env.cpp:61
virtual void msg_error_variable_name(std::ostream &oStdErr, const std::string &sVariableName) const
Print an error if variable name is invalid.
Definition command_env.cpp:85
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.
Definition command_env.cpp:81
Abstract base class for all shell commands.
Definition command.h:50
Represents an execution environment for a shell instance.
Definition shell_session.h:57
Defines the bs::command interface and built-in shell commands.
BashSpark main namespace.
Definition command.h:39
shell_status
Shell status codes.
Definition shell_status.h:47