Class: Papa::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/papa/command/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, options = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/papa/command/base.rb', line 9

def initialize(command, options = {})
  @command = command
  @silent = options.has_key?(:silent) ? options[:silent] : false
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



7
8
9
# File 'lib/papa/command/base.rb', line 7

def command
  @command
end

#exit_statusObject

Returns the value of attribute exit_status.



7
8
9
# File 'lib/papa/command/base.rb', line 7

def exit_status
  @exit_status
end

#silentObject

Returns the value of attribute silent.



7
8
9
# File 'lib/papa/command/base.rb', line 7

def silent
  @silent
end

#stderrObject

Returns the value of attribute stderr.



7
8
9
# File 'lib/papa/command/base.rb', line 7

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



7
8
9
# File 'lib/papa/command/base.rb', line 7

def stdout
  @stdout
end

Instance Method Details

#cleanupObject



29
30
31
# File 'lib/papa/command/base.rb', line 29

def cleanup
  # Override me
end

#failed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/papa/command/base.rb', line 37

def failed?
  exit_status != 0
end

#failure_messageObject



22
23
24
25
26
27
# File 'lib/papa/command/base.rb', line 22

def failure_message
  message = "Error while running #{command.bold}"
  Helper::Output.error message
  Helper::Output.error stderr
  message
end

#runObject



14
15
16
17
18
19
20
# File 'lib/papa/command/base.rb', line 14

def run
  return if command.nil?
  Helper::Output.stdout "Running #{command.bold}..." unless silent
  @stdout, @stderr, status = Open3.capture3(command)
  @exit_status = status.exitstatus
  self
end

#success?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/papa/command/base.rb', line 33

def success?
  !failed?
end