Class: Hotdog::Commands::SshAlike

Inherits:
Search show all
Defined in:
lib/hotdog/commands/ssh.rb

Direct Known Subclasses

Pssh, SingularSshAlike

Instance Attribute Summary

Attributes inherited from Search

#remote_command

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 define_options(optparse, options={})
  default_option(options, :ssh_options, {})
  default_option(options, :color, :auto)
  default_option(options, :max_parallelism, Parallel.processor_count * 2)
  default_option(options, :shuffle, false)
  default_option(options, :ssh_config, nil)
  optparse.on("-C", "Enable compression.") do |v|
    options[:ssh_options]["Compression"] = "yes"
  end
  optparse.on("-F SSH_CONFIG", "Specifies an alternative per-user SSH configuration file.") do |configfile|
    options[:ssh_config] = configfile
  end
  optparse.on("--dry-run", "Dry run.") do |v|
    options[: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)
    options[:ssh_options][ssh_option_key] = ssh_option_value
  end
  optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path|
    options[:ssh_options]["IdentityFile"] = path
  end
  optparse.on("-A", "Enable agent forwarding", TrueClass) do |b|
    options[:ssh_options]["ForwardAgent"] = "yes"
  end
  optparse.on("-p PORT", "Port of the remote host", Integer) do |port|
    options[:ssh_options]["Port"] = port
  end
  optparse.on("-u SSH_USER", "SSH login user name") do |user|
    options[:ssh_options]["User"] = user
  end
  optparse.on("-v", "--verbose", "Enable verbose ode") do |v|
    options[:verbose] = v
  end
  optparse.on("--filter=COMMAND", "Command to filter search result.") do |command|
    options[:filter_command] = command
  end
  optparse.on("-P PARALLELISM", "Max parallelism", Integer) do |n|
    options[:max_parallelism] = n
  end
  optparse.on("--color=WHEN", "--colour=WHEN", "Enable colors") do |color|
    options[:color] = color
  end
  optparse.on("--shuffle", "Shuffle result") do |v|
    options[: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=[], options={})
  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 = get_hosts_with_search_tags(result0, node)
  tuples = filter_hosts(tuples)
  validate_hosts!(tuples, fields)
  run_main(tuples.map {|tuple| tuple.first }, options)
end