class SSHKit::Interact::Command

Command wrapper

Public Class Methods

new(host, command) click to toggle source
# File lib/sshkit/interact/command.rb, line 5
def initialize(host, command)
  @host    = host
  @command = command
end

Public Instance Methods

execute() click to toggle source
# File lib/sshkit/interact/command.rb, line 19
def execute
  exec(to_cmd)
end
to_cmd() click to toggle source
# File lib/sshkit/interact/command.rb, line 10
def to_cmd
  [
    :ssh,
    *ssh_cmd_args,
    @host.hostname,
    %Q{'$SHELL -l -c "#{@command.to_command}"'}
  ].join(' ')
end

Private Instance Methods

forward_agent?() click to toggle source
# File lib/sshkit/interact/command.rb, line 41
def forward_agent?
  !!ssh_option(:forward_agent)
end
host_name() click to toggle source
# File lib/sshkit/interact/command.rb, line 29
def host_name
  ssh_option(:host_name)
end
keys() click to toggle source
# File lib/sshkit/interact/command.rb, line 49
def keys
  Array(ssh_option(:keys))
end
port() click to toggle source
# File lib/sshkit/interact/command.rb, line 33
def port
  ssh_option(:port)
end
proxy_command() click to toggle source
# File lib/sshkit/interact/command.rb, line 45
def proxy_command
  ssh_option(:proxy) ? ssh_option(:proxy).command_line_template : nil
end
ssh_cmd_args() click to toggle source
# File lib/sshkit/interact/command.rb, line 53
def ssh_cmd_args
  args = []

  args << '-t'
  args << '-A' if forward_agent?
  args << "-p #{port}" if port
  args << "-l #{user}"
  args << %Q{-o "ProxyCommand #{proxy_command}"} if proxy_command
  args << %Q{-o "HostName #{host_name}"} if host_name

  keys.each do |key|
    args << "-i #{key}"
  end

  args
end
ssh_option(attr_name) click to toggle source
# File lib/sshkit/interact/command.rb, line 25
def ssh_option(attr_name)
  (@host.netssh_options || {})[attr_name] || (@host.respond_to?(attr_name) ? @host.send(attr_name) : nil)
end
user() click to toggle source
# File lib/sshkit/interact/command.rb, line 37
def user
  ssh_option(:user)
end