diff --git a/src/server_env_manager.cpp b/src/server_env_manager.cpp index e6f21fb..f299ba9 100644 --- a/src/server_env_manager.cpp +++ b/src/server_env_manager.cpp @@ -176,8 +176,7 @@ bool server_env_manager::run_remote_template_command_and_capture_output(const st if (scommand.get_command_to_run().empty()) return false; - cMode mode = (silent ? cMode::Silent : cMode::None); - mode |= cMode::CaptureOutput; + cMode mode = cMode::CaptureOutput | cMode::RawCommand; return execute_ssh_command(get_SSH_INFO(), scommand, mode, &output); } diff --git a/src/utils/execute.cpp b/src/utils/execute.cpp index bd25e86..fe081af 100644 --- a/src/utils/execute.cpp +++ b/src/utils/execute.cpp @@ -88,6 +88,8 @@ bool execute_local_command(const sCommand & command, cMode mode, std::string * o if (hasFlag(mode, cMode::CaptureOutput)) { ASSERT_MSG(output != nullptr, "Capture output mode requires an output string to be provided"); + ASSERT_MSG(is_raw(mode), "Capture output mode requires raw command mode"); + ASSERT_MSG(!hasFlag(mode, cMode::Silent), "Silent mode is not allowed with capture output mode"); return execute_local_command_and_capture_output(command, output, mode); } diff --git a/src/utils/execute.hpp b/src/utils/execute.hpp index d0dba15..a7250d8 100644 --- a/src/utils/execute.hpp +++ b/src/utils/execute.hpp @@ -16,6 +16,22 @@ enum class cMode { CaptureOutput = 4, RawCommand = 8 }; +enum class cStyle { + Safe = 0, + Raw = 1 +}; + +inline cMode operator&(cMode lhs, cMode rhs) {return static_cast(static_cast(lhs) & static_cast(rhs));} +inline cMode operator+(cMode lhs, cMode rhs) {return static_cast(static_cast(lhs) | static_cast(rhs));} +inline cMode operator-(cMode lhs, cMode rhs) {return static_cast(static_cast(lhs) & ~static_cast(rhs));} +inline cMode operator|(cMode lhs, cMode rhs) {return static_cast(static_cast(lhs) | static_cast(rhs));} +inline cMode operator|=(cMode & lhs, cMode rhs) {return lhs = lhs | rhs;} +inline bool hasFlag(cMode mode, cMode flag) {return (mode & flag) == flag;} +inline bool is_safe(cStyle style) { return style == cStyle::Safe; } +inline bool is_raw(cStyle style) { return style == cStyle::Raw; } +inline bool is_raw(cMode mode) { return hasFlag(mode, cMode::RawCommand); } +inline cStyle getStyle(cMode mode) { return is_raw(mode) ? cStyle::Raw : cStyle::Safe; } + typedef struct sSSHInfo { std::string host; @@ -31,15 +47,7 @@ std::string makesafecmd(const std::string& command); // ------------------------------------------------------------------------------------------------ -enum class cStyle { - Safe = 0, - Raw = 1 -}; -inline cStyle getStyle(cMode mode) { return is_raw(mode) ? cStyle::Raw : cStyle::Safe; } -inline bool is_safe(cStyle style) { return style == cStyle::Safe; } -inline bool is_raw(cStyle style) { return style == cStyle::Raw; } -inline bool is_raw(cMode mode) { return hasFlag(mode, cMode::RawCommand); } // class to hold a command to run on the remote server. class sCommand { @@ -68,31 +76,6 @@ class sCommand { }; -// Bitwise AND operator for cMode -inline cMode operator&(cMode lhs, cMode rhs) { - return static_cast( - static_cast(lhs) & static_cast(rhs) - ); -} - -inline bool hasFlag(cMode mode, cMode flag) { - return (mode & flag) == flag; -} - -inline cMode operator-(cMode lhs, cMode rhs) { - return static_cast( - static_cast(lhs) & ~static_cast(rhs) - ); -} - -inline cMode operator|(cMode lhs, cMode rhs) { - return static_cast(static_cast(lhs) | static_cast(rhs)); -} - -inline cMode operator|=(cMode & lhs, cMode rhs) { - return lhs = lhs | rhs; -} - } // namespace dropshell