Class: Hotdog::Commands::Pssh

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

Constant Summary

Constants inherited from BaseCommand

BaseCommand::MASK_DATABASE, BaseCommand::MASK_QUERY, BaseCommand::PERSISTENT_DB

Instance Attribute Summary

Attributes inherited from Search

#remote_command

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



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
# File 'lib/hotdog/commands/pssh.rb', line 12

def define_options(optparse, options={})
  options[:options] = []
  options[:user] = nil
  options[:port] = nil
  options[:identity_file] = nil
  options[:forward_agent] = false
  options[:max_parallelism] = nil
  options[:color] = :auto

  optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |option|
    options[:options] += [option]
  end
  optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path|
    options[:identity_file] = path
  end
  optparse.on("-A", "Enable agent forwarding", TrueClass) do |b|
    options[:forward_agent] = b
  end
  optparse.on("-p PORT", "Port of the remote host", Integer) do |port|
    options[:port] = port
  end
  optparse.on("-u SSH_USER", "SSH login user name") do |user|
    options[:user] = user
  end
  optparse.on("-P PARALLELISM", "Max parallelism", Integer) do |n|
    options[:max_parallelism] = n
  end
  optparse.on("-v", "--verbose", "Enable verbose ode") do |v|
    options[:verbose] = v
  end
  optparse.on("--color=WHEN", "--colour=WHEN", "Enable colors") do |color|
    options[:color] = color
  end
end

#run(args = [], options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hotdog/commands/pssh.rb', line 47

def run(args=[], options={})
  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
    exec_command(result0, options)
  else
    STDERR.puts("no match found: #{expression}")
    exit(1)
  end
end