Class: Dk::Remote::BaseCmd
- Inherits:
-
Object
- Object
- Dk::Remote::BaseCmd
- Defined in:
- lib/dk/remote.rb
Defined Under Namespace
Classes: OutputLine
Instance Attribute Summary collapse
-
#cmd_str ⇒ Object
readonly
Returns the value of attribute cmd_str.
-
#host_ssh_args ⇒ Object
readonly
Returns the value of attribute host_ssh_args.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#local_cmds ⇒ Object
readonly
Returns the value of attribute local_cmds.
-
#ssh_args ⇒ Object
readonly
Returns the value of attribute ssh_args.
Instance Method Summary collapse
-
#initialize(local_cmd_or_spy_klass, cmd_str, opts) ⇒ BaseCmd
constructor
A new instance of BaseCmd.
- #output_lines ⇒ Object
- #run(input = nil) ⇒ Object
- #ssh_cmd_str(host) ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(local_cmd_or_spy_klass, cmd_str, opts) ⇒ BaseCmd
Returns a new instance of BaseCmd.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Attribute Details
#cmd_str ⇒ Object (readonly)
Returns the value of attribute cmd_str.
15 16 17 |
# File 'lib/dk/remote.rb', line 15 def cmd_str @cmd_str end |
#host_ssh_args ⇒ Object (readonly)
Returns the value of attribute host_ssh_args.
15 16 17 |
# File 'lib/dk/remote.rb', line 15 def host_ssh_args @host_ssh_args end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
15 16 17 |
# File 'lib/dk/remote.rb', line 15 def hosts @hosts end |
#local_cmds ⇒ Object (readonly)
Returns the value of attribute local_cmds.
15 16 17 |
# File 'lib/dk/remote.rb', line 15 def local_cmds @local_cmds end |
#ssh_args ⇒ Object (readonly)
Returns the value of attribute ssh_args.
15 16 17 |
# File 'lib/dk/remote.rb', line 15 def ssh_args @ssh_args end |
Instance Method Details
#output_lines ⇒ Object
67 68 69 70 71 |
# 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) ⇒ Object
43 44 45 46 47 |
# 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) ⇒ Object
39 40 41 |
# 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 ⇒ Object
55 56 57 58 59 |
# 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 ⇒ Object
49 50 51 52 53 |
# 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? ⇒ Boolean
61 62 63 64 65 |
# 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 ⇒ Object
37 |
# File 'lib/dk/remote.rb', line 37 def to_s; self.cmd_str; end |