BashSpark
Loading...
Searching...
No Matches
command_var.h
Go to the documentation of this file.
1
27#pragma once
28
29#include "BashSpark/command.h"
30
31namespace bs {
38 class command_getvar : public command {
39 public:
44 : command("getvar") {
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
79
86 class command_setvar : public command {
87 public:
92 : command("setvar") {
93 }
94
106 [[nodiscard]] shell_status run(
107 const std::span<const std::string> &vArgs,
108 shell_session &oSession
109 ) const override;
110
111 public:
117 virtual void msg_error_param_number(std::ostream &oStdErr, std::size_t nArgs) const;
118
124 virtual void msg_error_variable_name(std::ostream &oStdErr, const std::string &sVariableName) const;
125 };
126}
Retrieves the value of an local variable.
Definition command_var.h:38
shell_status run(const std::span< const std::string > &vArgs, shell_session &oSession) const override
Prints the local variable value on stdout. If the local variable does not exist, does nothing.
Definition command_var.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_var.cpp:53
command_getvar()
Constructs command.
Definition command_var.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_var.cpp:57
Sets the value of a local variable.
Definition command_var.h:86
shell_status run(const std::span< const std::string > &vArgs, shell_session &oSession) const override
Sets the local variable value. If the local variable does not exist, creates it.
Definition command_var.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_var.cpp:85
command_setvar()
Constructs command.
Definition command_var.h:91
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_var.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