Class: CommandLine::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/command_line/result.rb

Overview

The result returned from running command_line.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout, stderr, status) ⇒ Result

Returns a new instance of Result.



6
7
8
9
10
# File 'lib/command_line/result.rb', line 6

def initialize(stdout, stderr, status)
  @stdout = stdout
  @stderr = stderr
  @status = status
end

Instance Attribute Details

#stderrString (readonly)

The complete contents of stderr after running the application.

Examples:

command_line('grep').stderr
# => "usage: grep ..."

Returns:

  • (String)


28
29
30
# File 'lib/command_line/result.rb', line 28

def stderr
  @stderr
end

#stdoutString (readonly)

The complete contents of stdout after running the application.

Examples:

command_line('echo', 'hi').stdout
# => "hi\n"

Returns:

  • (String)


19
20
21
# File 'lib/command_line/result.rb', line 19

def stdout
  @stdout
end

Instance Method Details

#exited?Boolean

Returns true if the application exited normally.

Examples:

command_line('grep').exited?

Returns:

  • (Boolean)


36
37
38
# File 'lib/command_line/result.rb', line 36

def exited?
  @status.exited?
end

#exitstatusInteger?

The numeric exit status of the application if it exited normally.

Examples:

command_line('echo', 'hi').exitstatus
# => 0
command_line('grep').exitstatus
# => 2

Returns:

  • (Integer, nil)


49
50
51
# File 'lib/command_line/result.rb', line 49

def exitstatus
  @status.exitstatus
end

#failure?Boolean

Returns true if the command failed to exit normally or exited with a failing status.

Examples:

command_line('grep').failure?
# => true

Returns:

  • (Boolean)


72
73
74
# File 'lib/command_line/result.rb', line 72

def failure?
  !success?
end

#success?Boolean

Returns true if the command exited normally with a success status.

Examples:

command_line('echo', 'hi').success?
# => true

Returns:

  • (Boolean)


60
61
62
# File 'lib/command_line/result.rb', line 60

def success?
  !@status.nil? && @status.success?
end