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.



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

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

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



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

def command
  @command
end

#exitstatusObject (readonly)

Returns the value of attribute exitstatus.



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

def exitstatus
  @exitstatus
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#error!Object



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

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

#error?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 35

def error?
  exitstatus != 0
end

#stderrObject



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

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

#stdoutObject



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

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