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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 33

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