Class: PolySSH::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/polyssh/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCli

Returns a new instance of Cli.



23
24
25
26
27
# File 'lib/polyssh/cli.rb', line 23

def initialize
  @chain = NodeList.new
  @commands = []
  @options = {}
end

Instance Attribute Details

#chainObject (readonly)

Returns the value of attribute chain.



9
10
11
# File 'lib/polyssh/cli.rb', line 9

def chain
  @chain
end

#commandsObject (readonly)

Returns the value of attribute commands.



9
10
11
# File 'lib/polyssh/cli.rb', line 9

def commands
  @commands
end

Class Method Details

.start(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/polyssh/cli.rb', line 11

def self.start args
  app = self.new
  app.parse_cmdline args

  puts "Building SSH hops...".yellow
  app.build_commands app.chain
  #app.commands.each{|x| puts x }

  puts "Running SSH hops...".yellow
  app.run_commands app.commands
end

Instance Method Details

#build_commands(chain) ⇒ Object



43
44
45
46
# File 'lib/polyssh/cli.rb', line 43

def build_commands chain
  @commands = chain.accept(CommandBuilder.new)
  return @commands
end

#parse_cmdline(args) ⇒ Object



29
30
31
32
# File 'lib/polyssh/cli.rb', line 29

def parse_cmdline args
  _parse_cmdline_options args
  _parse_cmdline_hops args
end

#run_commands(commands) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/polyssh/cli.rb', line 34

def run_commands commands
  @commands[0..-2].each do |baseport,cmd|
    fork { exec cmd + " >/dev/null 2>&1 " }
    _wait_active_port baseport
  end
  _baseport, cmd = @commands.last
  system cmd
end