Class: Sshify::Commands::Connect
- Inherits:
-
Sshify::Command
- Object
- Sshify::Command
- Sshify::Commands::Connect
- Defined in:
- lib/sshify/commands/connect.rb
Instance Method Summary collapse
- #execute(input: $stdin, output: $stdout) ⇒ Object
-
#initialize(options) ⇒ Connect
constructor
A new instance of Connect.
Methods inherited from Sshify::Command
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(options) ⇒ Connect
10 11 12 13 14 15 16 17 |
# File 'lib/sshify/commands/connect.rb', line 10 def initialize() = @config = TTY::Config.new @config.filename = "sshify-config" @config.extname = ".yml" @config.append_path Dir.home end |
Instance Method Details
#execute(input: $stdin, output: $stdout) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sshify/commands/connect.rb', line 19 def execute(input: $stdin, output: $stdout) @config ||= self.class.new().config @config.read if @config.persisted? selection = prompt.select("Select one to connect") do || @config.read.keys.each do |server_name| .choice server_name end end server = @config.fetch(selection) user = server['user'].first server_ip = server['server_ip'].first exec("ssh #{user}@#{server_ip}") end |