Class: Brut::CLI::ExecuteResult

Inherits:
Object
  • Object
show all
Defined in:
lib/brut/cli/execute_result.rb

Overview

Wraps the result of calling Brut::CLI::Commands::BaseCommand#execute and interpreting it as an exit code

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ ExecuteResult

Returns a new instance of ExecuteResult.



4
5
6
7
8
9
10
# File 'lib/brut/cli/execute_result.rb', line 4

def initialize(&block)
  @actual_result = begin
                     block.()
                   rescue Brut::CLI::Error => ex
                     ex
                   end
end

Instance Method Details

#exit_status {|error_message| ... } ⇒ Integer

Get the exit status for the given result. This will call the block given with an error message if there is one.

Yields:

  • (error_message)

    If a block is passed, it's called when a Brut::CLI::Error was the return value of the command, so that you can access the message of the error.

Yield Parameters:

Returns:

  • (Integer)

    value betweeen 0 and 255 representing the exit status to use based on the value the command returned.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/brut/cli/execute_result.rb', line 24

def exit_status(&when_error_message)
  when_error_message ||= ->(*){}
  case @actual_result
  in Integer
    @actual_result
  in Brut::CLI::SystemExecError
    when_error_message.(@actual_result.message)
    @actual_result.exit_status
  in Brut::CLI::Error
    when_error_message.(@actual_result.message)
    1
  else
    0
  end
end

#failed?Boolean

Returns:

  • (Boolean)


13
# File 'lib/brut/cli/execute_result.rb', line 13

def failed?  = !self.success?

#success?Boolean

Returns:

  • (Boolean)


12
# File 'lib/brut/cli/execute_result.rb', line 12

def success? =  self.exit_status == 0