Class: Convoy::Formatter::ShellCommandExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/convoy/formatter/shell_command_executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ ShellCommandExecutor

Returns a new instance of ShellCommandExecutor.



8
9
10
# File 'lib/convoy/formatter/shell_command_executor.rb', line 8

def initialize(command)
    @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/convoy/formatter/shell_command_executor.rb', line 6

def command
  @command
end

Instance Method Details

#execute_in_current_shell(success_callback = nil, error_callback = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/convoy/formatter/shell_command_executor.rb', line 12

def execute_in_current_shell(success_callback = nil, error_callback = nil)
    begin
        result         = `#{command}`
        process_status = $?
        raise Convoy::InternalError.new("Shell command exited with a non-zero (#{process_status.exitstatus}) exit code") if process_status.exitstatus != 0
        success_callback.call(command, result) if success_callback
    rescue => e
        error_callback.call(command, e) if error_callback
        nil
    end
end