114 std::istream &oCommand,
125 const std::string &sCommand,
136 const std::string_view &sCommand,
152 void set_command(std::unique_ptr<command> &&pCommand);
164 template<
typename CommandT,
typename... Args>
166 static_assert(std::is_base_of_v<command, CommandT>,
167 "Template set_command only takes command derived classes.");
168 std::unique_ptr<command> pCommand(
new CommandT(std::forward<Args>(args)...));
177 [[nodiscard]] std::unique_ptr<command>
remove_command(
const std::string &sCommand);
234 std::unordered_map<std::
string, std::unique_ptr<
command>,
shell_hash> m_mCommands;
236 mutable std::mutex m_oExecutionMutex;
238 bool m_bStopOnCommandNotFound = true;
Abstract base class for all shell commands.
Definition command.h:50
Exception class for handling shell-specific errors.
Definition shell_parser_exception.h:45
Represents an execution environment for a shell instance.
Definition shell_session.h:57
A simplified shell environment inspired by Bash.
Definition shell.h:63
static constexpr std::size_t MAX_DEPTH
Maximum depth the command interpreter can reach.
Definition shell.h:66
virtual void msg_error_syntax_error(const shell_session &oSession, const shell_parser_exception &oException) const
Displays the error message for “syntax errors”.
Definition shell.cpp:111
virtual void msg_error_command_not_found(shell_session &oSession, const std::string &sCommand) const
Displays the error message for “command not found”.
Definition shell.cpp:103
void erase_command(const std::string &sCommand)
Erases a command by its string.
Definition shell.cpp:86
virtual void msg_error_invalid_function_name(shell_session &oSession, const std::string &sFunction) const
Displays the error message for “function name invalid”.
Definition shell.cpp:107
bool get_stop_on_command_not_found() const noexcept
Checks if execution stops on command not found.
Definition shell.cpp:95
shell()
Construct bash object.
Definition shell.h:97
void set_stop_on_command_not_found(bool bStopOnCommandNotFound) noexcept
Sets whether to stop execution on command not found.
Definition shell.cpp:99
void set_command(Args &&... args)
Creates and sets a command of type CommandT.
Definition shell.h:165
std::unique_ptr< command > remove_command(const std::string &sCommand)
Removes a command and returns it.
Definition shell.cpp:76
static constexpr std::string_view BASH_ERROR_COMMAND_NOT_FOUND
Message name for bash command not found.
Definition shell.h:72
static shell_status run(std::istream &oCommand, shell_session &oSession)
Runs a command or script.
Definition shell.cpp:150
const command * get_command(const std::string &sCommand) const noexcept
Retrieves a command pointer by its string.
Definition shell.cpp:65
static constexpr std::size_t DEFAULT_COMMAND_HASH_TABLE_SIZE
Default size for the command hash table.
Definition shell.h:75
static constexpr std::string_view BASH_ERROR_SYNTAX
Message name for bash syntax error.
Definition shell.h:69
static std::unique_ptr< shell > make_default_shell()
Construct bash object.
Definition shell.cpp:50
void set_command(std::unique_ptr< command > &&pCommand)
Sets a command using a unique pointer. Overwrites previous command.
Definition shell.cpp:72
virtual ~shell()=default
Destruct bash object.
Defines the bs::command interface and built-in shell commands.
BashSpark main namespace.
Definition command.h:39
constexpr std::size_t SHELL_MAX_DEPTH
Maximum depth allowed for shell.
Definition shell_status.h:41
shell_status
Shell status codes.
Definition shell_status.h:47
Defines the bs::shell_hash functor implementing a 64-bit FNV-1a hash.
Defines class shell_exception.
Defines the class bs::shell_session.
Custom hash functor for strings using the 64-bit FNV-1a algorithm.
Definition shell_hash.h:46