Module: NexusSW::LXD::Transport::Mixins::Helpers::ExecuteMixin

Included in:
Local, Rest
Defined in:
lib/nexussw/lxd/transport/mixins/helpers/execute.rb

Defined Under Namespace

Classes: ExecuteResult, InteractiveResult

Instance Method Summary collapse

Instance Method Details

#execute(command, options = {}, &block) ⇒ Object

LocalTransport does not have the users mixin, so code the ‘su` command on the rest & cli transports directly



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 41

def execute(command, options = {}, &block)
  options ||= {}
  return execute_chunked(command, options) if options[:capture] == false && !block_given?

  capture_options = { stdout: "", stderr: "" }
  capture_options[:capture] = block if block_given?
  capture_options[:capture] ||= options[:capture] if options[:capture].respond_to? :call
  # capture_options[:capture] ||= options[:stream] if options[:stream].respond_to? :call
  capture_options[:capture] ||= proc do |stdout_chunk, stderr_chunk|
    capture_options[:stdout] += stdout_chunk if stdout_chunk
    capture_options[:stderr] += stderr_chunk if stderr_chunk
  end

  execute_chunked(command, options.merge(capture_options: capture_options), &capture_options[:capture])
end