Class: Gaptool::SSHCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/gaptool_client/commands.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# 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