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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ ExecuteResult

Returns a new instance of ExecuteResult.



5
6
7
8
9
10
11
12
13
14
# File 'lib/brut/cli/execute_result.rb', line 5

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

                   end
end

Instance Attribute Details

#actual_resultObject (readonly)

Returns the value of attribute actual_result.



4
5
6
# File 'lib/brut/cli/execute_result.rb', line 4

def actual_result
  @actual_result
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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/brut/cli/execute_result.rb', line 28

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)


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

def failed?  = !self.success?

#success?Boolean

Returns:

  • (Boolean)


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

def success? =  self.exit_status == 0