Module: Diffend::Shell
- Defined in:
- lib/diffend/shell.rb
Class Method Summary collapse
-
.call(command_with_options, raise_on_invalid_exit: true) ⇒ Hash
Allows to execute shell commands and handle errors, etc later (won’t raise any errors but instead will catch all things).
-
.call_in_path(path, command, raise_on_invalid_exit: true) ⇒ Hash
Hash with 3 keys describing output (stdout, stderr, exit_code).
Class Method Details
.call(command_with_options, raise_on_invalid_exit: true) ⇒ Hash
Allows to execute shell commands and handle errors, etc later
(won't raise any errors but instead will catch all things)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/diffend/shell.rb', line 19 def call(, raise_on_invalid_exit: true) stdout_str, stderr_str, status = Open3.capture3() result = { stdout: stdout_str, stderr: stderr_str, exit_code: status.exitstatus } raise Diffend::Errors::FailedShellCommand, result.values.join(': ') \ if raise_on_invalid_exit && result[:exit_code] != 0 result end |
.call_in_path(path, command, raise_on_invalid_exit: true) ⇒ Hash
Returns hash with 3 keys describing output (stdout, stderr, exit_code).
38 39 40 41 |
# File 'lib/diffend/shell.rb', line 38 def call_in_path(path, command, raise_on_invalid_exit: true) command = ['cd', path.to_s, '&&', command] call(command.join(' '), raise_on_invalid_exit: raise_on_invalid_exit) end |