module NexusSW::LXD::Transport::Mixins::Helpers::ExecuteMixin

Public Instance Methods

execute(command, options = {}, &block) click to toggle source

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

# 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