Class: SSHKit::Interactive::Command
- Inherits:
-
Object
- Object
- SSHKit::Interactive::Command
- Defined in:
- lib/sshkit/interactive/command.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#remote_command ⇒ Object
readonly
Returns the value of attribute remote_command.
Instance Method Summary collapse
- #execute ⇒ Object
- #hostname ⇒ Object
-
#initialize(host, remote_command = nil) ⇒ Command
constructor
remote_command can be an SSHKit::Command or a String.
- #netssh_options ⇒ Object
- #options ⇒ Object
- #options_str ⇒ Object
- #remote_command_str ⇒ Object
- #to_s ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(host, remote_command = nil) ⇒ Command
remote_command can be an SSHKit::Command or a String
7 8 9 10 |
# File 'lib/sshkit/interactive/command.rb', line 7 def initialize(host, remote_command=nil) @host = host @remote_command = remote_command end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
4 5 6 |
# File 'lib/sshkit/interactive/command.rb', line 4 def host @host end |
#remote_command ⇒ Object (readonly)
Returns the value of attribute remote_command.
4 5 6 |
# File 'lib/sshkit/interactive/command.rb', line 4 def remote_command @remote_command end |
Instance Method Details
#execute ⇒ Object
64 65 66 |
# File 'lib/sshkit/interactive/command.rb', line 64 def execute system(self.to_s) end |
#hostname ⇒ Object
20 21 22 |
# File 'lib/sshkit/interactive/command.rb', line 20 def hostname self.host.hostname end |
#netssh_options ⇒ Object
12 13 14 |
# File 'lib/sshkit/interactive/command.rb', line 12 def self.host. end |
#options ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sshkit/interactive/command.rb', line 24 def opts = [] opts << '-A' if [:forward_agent] if [:keys] [:keys].each do |k| opts << "-i #{k}" end end opts << "-l #{user}" if user opts << %{-o "PreferredAuthentications #{netssh_options[:auth_methods].join(',')}"} if [:auth_methods] opts << %{-o "ProxyCommand #{netssh_options[:proxy].command_line_template}"} if [:proxy] opts << "-p #{netssh_options[:port]}" if [:port] opts << '-t' if self.remote_command opts end |
#options_str ⇒ Object
41 42 43 |
# File 'lib/sshkit/interactive/command.rb', line 41 def self..join(' ') end |
#remote_command_str ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/sshkit/interactive/command.rb', line 45 def remote_command_str if self.remote_command %{"#{self.remote_command}"} else '' end end |
#to_s ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sshkit/interactive/command.rb', line 53 def to_s parts = [ 'ssh', self., self.hostname, self.remote_command_str ] parts.reject(&:empty?).join(' ') end |
#user ⇒ Object
16 17 18 |
# File 'lib/sshkit/interactive/command.rb', line 16 def user self.host.user end |