Class: Hotdog::Commands::SshAlike
- Inherits:
-
Search
- Object
- BaseCommand
- Search
- Hotdog::Commands::SshAlike
- Defined in:
- lib/hotdog/commands/ssh.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Search
Attributes inherited from BaseCommand
#application, #logger, #options, #persistent_db_path
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
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hotdog/commands/ssh.rb', line 12 def (optparse, ={}) default_option(, :ssh_options, {}) default_option(, :color, :auto) default_option(, :max_parallelism, Parallel.processor_count * 2) default_option(, :shuffle, false) default_option(, :ssh_config, nil) optparse.on("-C", "Enable compression.") do |v| [:ssh_options]["Compression"] = "yes" end optparse.on("-F SSH_CONFIG", "Specifies an alternative per-user SSH configuration file.") do |configfile| [:ssh_config] = configfile end optparse.on("--dry-run", "Dry run.") do |v| [:dry_run] = v end optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |ssh_option| ssh_option_key, ssh_option_value = ssh_option.split("=", 2) [:ssh_options][ssh_option_key] = ssh_option_value end optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path| [:ssh_options]["IdentityFile"] = path end optparse.on("-A", "Enable agent forwarding", TrueClass) do |b| [:ssh_options]["ForwardAgent"] = "yes" end optparse.on("-p PORT", "Port of the remote host", Integer) do |port| [:ssh_options]["Port"] = port end optparse.on("-u SSH_USER", "SSH login user name") do |user| [:ssh_options]["User"] = user end optparse.on("-v", "--verbose", "Enable verbose ode") do |v| [:verbose] = v end optparse.on("--filter=COMMAND", "Command to filter search result.") do |command| [:filter_command] = command end optparse.on("-P PARALLELISM", "Max parallelism", Integer) do |n| [:max_parallelism] = n end optparse.on("--color=WHEN", "--colour=WHEN", "Enable colors") do |color| [:color] = color end optparse.on("--shuffle", "Shuffle result") do |v| [:shuffle] = v end end |
#run(args = [], options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hotdog/commands/ssh.rb', line 60 def run(args=[], ={}) expression = rewrite_expression(args.join(" ").strip) begin node = parse(expression) rescue Parslet::ParseFailed => error STDERR.puts("syntax error: " + error.cause.ascii_tree) exit(1) end result0 = evaluate(node, self) tuples, fields = (result0, node) tuples = filter_hosts(tuples) validate_hosts!(tuples, fields) run_main(tuples.map {|tuple| tuple.first }, ) end |