class Dk::Remote::BaseCmd
Constants
- OutputLine
Attributes
cmd_str[R]
host_ssh_args[R]
hosts[R]
local_cmds[R]
ssh_args[R]
Public Class Methods
new(local_cmd_or_spy_klass, cmd_str, opts)
click to toggle source
# File lib/dk/remote.rb, line 17 def initialize(local_cmd_or_spy_klass, cmd_str, opts) opts ||= {} if nil_or_empty_or_missing_hosts(opts[:hosts]) raise NoHostsError, "no hosts to run cmd on (#{opts[:hosts].inspect})" end @hosts = opts[:hosts].sort @ssh_args = opts[:ssh_args] || Dk::Config::DEFAULT_SSH_ARGS.dup @host_ssh_args = opts[:host_ssh_args] || Dk::Config::DEFAULT_HOST_SSH_ARGS.dup @cmd_str = cmd_str @local_cmds = @hosts.inject({}) do |cmds, host| cmds[host] = local_cmd_or_spy_klass.new(self.ssh_cmd_str(host), { :env => opts[:env], :dry_tree_run => opts[:dry_tree_run] }) cmds end end
Public Instance Methods
output_lines()
click to toggle source
# File lib/dk/remote.rb, line 67 def output_lines self.hosts.inject([]) do |lines, host| lines + build_output_lines(host, @local_cmds[host].output_lines) end end
run(input = nil)
click to toggle source
# File lib/dk/remote.rb, line 43 def run(input = nil) self.hosts.each{ |host| @local_cmds[host].scmd.start(input) } self.hosts.each{ |host| @local_cmds[host].scmd.wait } self end
ssh_cmd_str(host)
click to toggle source
# File lib/dk/remote.rb, line 39 def ssh_cmd_str(host) build_ssh_cmd_str(@cmd_str, host, @ssh_args, @host_ssh_args) end
stderr()
click to toggle source
# File lib/dk/remote.rb, line 55 def stderr self.hosts.inject('') do |err, host| err.empty? ? @local_cmds[host].stderr.to_s : err end end
stdout()
click to toggle source
# File lib/dk/remote.rb, line 49 def stdout self.hosts.inject('') do |out, host| out.empty? ? @local_cmds[host].stdout.to_s : out end end
success?()
click to toggle source
# File lib/dk/remote.rb, line 61 def success? self.hosts.inject(true) do |success, host| success && @local_cmds[host].success? end end
to_s()
click to toggle source
# File lib/dk/remote.rb, line 37 def to_s; self.cmd_str; end
Private Instance Methods
build_output_lines(host, local_cmd_output_lines)
click to toggle source
# File lib/dk/remote.rb, line 86 def build_output_lines(host, local_cmd_output_lines) local_cmd_output_lines.map{ |ol| OutputLine.new(host, ol.name, ol.line) } end
build_ssh_cmd_str(cmd_str, host, args, host_args)
click to toggle source
escape everything properly; run in sh to ensure full profile is loaded
# File lib/dk/remote.rb, line 82 def build_ssh_cmd_str(cmd_str, host, args, host_args) Dk::Remote.ssh_cmd_str(cmd_str, host, args, host_args) end
nil_or_empty_or_missing_hosts(h)
click to toggle source
# File lib/dk/remote.rb, line 75 def nil_or_empty_or_missing_hosts(h) h.nil? || !h.respond_to?(:empty?) || h.empty? || !h.respond_to?(:select) || h.select(&:nil?).size > 0 end