Class: NexusSW::LXD::Transport::Mixins::Helpers::ExecuteMixin::ExecuteResult

Inherits:
Object
  • Object
show all
Defined in:
lib/nexussw/lxd/transport/mixins/helpers/execute.rb

Direct Known Subclasses

InteractiveResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, options, exitstatus) ⇒ ExecuteResult

Returns a new instance of ExecuteResult.



8
9
10
11
12
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 8

def initialize(command, options, exitstatus)
  @command = command
  @options = options || {}
  @exitstatus = exitstatus
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



14
15
16
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 14

def command
  @command
end

#exitstatusObject (readonly)

Returns the value of attribute exitstatus.



14
15
16
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 14

def exitstatus
  @exitstatus
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 14

def options
  @options
end

Instance Method Details

#error!Object



24
25
26
27
28
29
30
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 24

def error!
  return self if exitstatus == 0
  msg = "Error: '#{command}' failed with exit code #{exitstatus}.\n"
  msg += "STDOUT: #{stdout}" if stdout.is_a?(String) && !stdout.empty?
  msg += "STDERR: #{stderr}" if stderr.is_a?(String) && !stderr.empty?
  raise msg
end

#stderrObject



20
21
22
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 20

def stderr
  options[:capture_options][:stderr] if options.key? :capture_options
end

#stdoutObject



16
17
18
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 16

def stdout
  options[:capture_options][:stdout] if options.key? :capture_options
end