Class: Moonshot::SSHCommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/moonshot/ssh_command_builder.rb

Overview

Create an ssh command from configuration.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(ssh_config, instance_id) ⇒ SSHCommandBuilder

Returns a new instance of SSHCommandBuilder.



10
11
12
13
# File 'lib/moonshot/ssh_command_builder.rb', line 10

def initialize(ssh_config, instance_id)
  @config = ssh_config
  @instance_id = instance_id
end

Instance Method Details

#build(command = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/moonshot/ssh_command_builder.rb', line 15

def build(command = nil)
  cmd = ['ssh', '-t']
  cmd << "-i #{@config.ssh_identity_file}" if @config.ssh_identity_file
  cmd << "-l #{@config.ssh_user}" if @config.ssh_user
  cmd << instance_ip
  cmd << Shellwords.escape(command) if command
  Result.new(cmd.join(' '), instance_ip)
end