class Hotdog::Commands::SingularSshAlike
Public Instance Methods
define_options(optparse, options={})
click to toggle source
Calls superclass method
Hotdog::Commands::SshAlike#define_options
# File lib/hotdog/commands/ssh.rb, line 233 def define_options(optparse, options={}) super options[:index] = nil optparse.on("-n", "--index INDEX", "Use this index of host if multiple servers are found", Integer) do |index| options[:index] = index end end
Private Instance Methods
filter_hosts(tuples)
click to toggle source
rewriting `options` as SLICE expression won't work as expected with hosts' status since the result may be filtered again with using the status, the filtering needs to be done after the `evaluate()`.
for now we need to keep using `filter_hosts()` in favor of `rewrite_expression() to do the filtering based on status filtering.
Calls superclass method
Hotdog::Commands::SshAlike#filter_hosts
# File lib/hotdog/commands/ssh.rb, line 248 def filter_hosts(tuples) tuples = super if options[:index] and options[:index] < tuples.length filtered_tuples = tuples.reject.with_index { |tuple, i| i == options[:index] } logger.warn("filtered host(s): #{filtered_tuples.map { |tuple| tuple.first }.inspect}") [tuples[options[:index]]] else tuples end end
run_main(hosts, options={})
click to toggle source
# File lib/hotdog/commands/ssh.rb, line 269 def run_main(hosts, options={}) cmdline = build_command_string(hosts.first, @remote_command, options) logger.debug("execute: #{cmdline}") if options[:dry_run] STDOUT.puts(cmdline) exit(0) else exec(cmdline) end exit(127) end
validate_hosts!(tuples, fields)
click to toggle source
Calls superclass method
Hotdog::Commands::SshAlike#validate_hosts!
# File lib/hotdog/commands/ssh.rb, line 259 def validate_hosts!(tuples, fields) super if tuples.length != 1 result = tuples.each_with_index.map { |tuple, i| [i] + tuple } STDERR.print(format(result, fields: ["index"] + fields)) logger.error("found %d candidates. use '-n INDEX' option to select one." % result.length) exit(1) end end