class Gaptool::SSHCommand

Public Instance Methods

execute() click to toggle source
# File lib/gaptool_client/commands.rb, line 172
def execute
  puts Rainbow('tmux support has been removed').yellow if tmux?
  nodes = Gaptool::API.query_nodes(hidden: true,
                                   instance: instance,
                                   environment: environment,
                                   role: role)

  if first? || (nodes.length == 1 && !instance)
    puts Rainbow('No instance specified, but only one instance in cluster or first forced').green
    node = nodes.first
  elsif !instance
    nodes.each_index do |i|
      puts "#{i}: #{nodes[i]['instance']}"
    end
    print Rainbow('Select a node: ').cyan
    node = nodes[$stdin.gets.chomp.to_i]
    error 'Invalid selection' if node.nil?
  else
    node = nodes.first
  end
  Gaptool::SSH.update_config_for(node)
  system "ssh #{node['instance']}"
end