Class: Roast::Workflow::CommandExecutor
- Inherits:
-
Object
- Object
- Roast::Workflow::CommandExecutor
- Defined in:
- lib/roast/workflow/command_executor.rb
Defined Under Namespace
Classes: CommandExecutionError, NullLogger
Constant Summary collapse
- BASH_COMMAND_REGEX =
/^\$\((.*)\)$/m
Instance Method Summary collapse
- #execute(command_string, exit_on_error: true) ⇒ Object
-
#initialize(logger: nil) ⇒ CommandExecutor
constructor
A new instance of CommandExecutor.
Constructor Details
#initialize(logger: nil) ⇒ CommandExecutor
Returns a new instance of CommandExecutor.
19 20 21 |
# File 'lib/roast/workflow/command_executor.rb', line 19 def initialize(logger: nil) @logger = logger || NullLogger.new end |
Instance Method Details
#execute(command_string, exit_on_error: true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/roast/workflow/command_executor.rb', line 23 def execute(command_string, exit_on_error: true) command = extract_command(command_string) output = %x(#{command}) exit_status = $CHILD_STATUS.exitstatus handle_execution_result( command: command, output: output, exit_status: exit_status, success: $CHILD_STATUS.success?, exit_on_error: exit_on_error, ) rescue ArgumentError, CommandExecutionError raise rescue => e handle_execution_error( command: command, error: e, exit_on_error: exit_on_error, ) end |