Class: Hotdog::Commands::Ssh
- Inherits:
-
Search
- Object
- BaseCommand
- Search
- Hotdog::Commands::Ssh
- Defined in:
- lib/hotdog/commands/ssh.rb
Constant Summary
Constants inherited from BaseCommand
BaseCommand::MASK_DATABASE, BaseCommand::MASK_QUERY, BaseCommand::PERSISTENT_DB
Instance Attribute Summary
Attributes inherited from Search
Attributes inherited from BaseCommand
#application, #logger, #options
Instance Method Summary collapse
Methods inherited from Search
#evaluate, #get_hosts_with_search_tags, #parse, #parse_options
Methods inherited from BaseCommand
#execute, #fixed_string?, #initialize, #parse_options, #reload
Constructor Details
This class inherits a constructor from Hotdog::Commands::BaseCommand
Instance Method Details
#define_options(optparse, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hotdog/commands/ssh.rb', line 11 def (optparse, ={}) [:index] = nil [:options] = [] [:user] = nil [:port] = nil [:identity_file] = nil [:forward_agent] = false optparse.on("-n", "--index INDEX", "Use this index of host if multiple servers are found", Integer) do |index| [:index] = index end optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |option| [:options] += [option] end optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path| [:identity_file] = path end optparse.on("-A", "Enable agent forwarding", TrueClass) do |b| [:forward_agent] = b end optparse.on("-p PORT", "Port of the remote host", Integer) do |port| [:port] = port end optparse.on("-u SSH_USER", "SSH login user name") do |user| [:user] = user end optparse.on("-v", "--verbose", "Enable verbose ode") do |v| [:verbose] = v end end |
#run(args = [], options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hotdog/commands/ssh.rb', line 42 def run(args=[], ={}) expression = args.join(" ").strip if expression.empty? # return everything if given expression is empty expression = "*" end begin node = parse(expression) rescue Parslet::ParseFailed => error STDERR.puts("syntax error: " + error.cause.ascii_tree) exit(1) end result0 = evaluate(node, self) if 0 < result0.length if result0.length == 1 exec_command([result0.first], ) else if [:index] and [:index] < result0.length exec_command([result0[[:index]]], ) else result, fields = (result0, node) # add "index" field result = result.each_with_index.map { |host, i| [i] + host } fields = ["index"] + fields STDERR.print(format(result, fields: fields)) logger.info("found %d host(s)." % result.length) exit(1) end end else STDERR.puts("no match found: #{expression}") exit(1) end exit(127) end |