lib/deployml/remote_shell.rb in deployml-0.4.2 vs lib/deployml/remote_shell.rb in deployml-0.5.0
- old
+ new
@@ -1,20 +1,16 @@
+require 'deployml/exceptions/invalid_config'
require 'deployml/shell'
require 'addressable/uri'
module DeploYML
#
# Represents a shell running on a remote server.
#
- class RemoteShell
+ class RemoteShell < Shell
- include Shell
-
- # The URI of the remote shell
- attr_reader :uri
-
# The history of the Remote Shell
attr_reader :history
#
# Initializes a remote shell session.
@@ -27,35 +23,28 @@
#
# @yieldparam [ShellSession] session
# The remote shell session.
#
def initialize(uri,&block)
- case uri
- when Addressable::URI
- @uri = uri
- else
- @uri = Addressable::URI.parse(uri.to_s)
- end
-
@history = []
- super(&block)
+ super(uri,&block)
replay if block
end
#
# Enqueues a program to be ran in the session.
#
# @param [String] program
# The name or path of the program to run.
#
- # @param [Array<String>] args
+ # @param [Array<String>] arguments
# Additional arguments for the program.
#
- def run(program,*args)
- @history << [program, *args]
+ def run(program,*arguments)
+ @history << [program, *arguments]
end
#
# Enqueues an `echo` command to be ran in the session.
#
@@ -102,24 +91,31 @@
# Converts the URI to one compatible with SSH.
#
# @return [String]
# The SSH compatible URI.
#
+ # @raise [InvalidConfig]
+ # The URI of the shell does not have a host component.
+ #
def ssh_uri
+ unless @uri.host
+ raise(InvalidConfig,"URI does not have a host: #{@uri}",caller)
+ end
+
new_uri = @uri.host
new_uri = "#{@uri.user}@#{new_uri}" if @uri.user
return new_uri
end
#
# Starts a SSH session with the destination server.
#
- # @param [Array] args
+ # @param [Array] arguments
# Additional arguments to pass to SSH.
#
- def ssh(*args)
+ def ssh(*arguments)
options = []
# Add the -p option if an alternate destination port is given
if @uri.port
options += ['-p', @uri.port.to_s]
@@ -127,10 +123,10 @@
# append the SSH URI
options << ssh_uri
# append the additional arguments
- args.each { |arg| options << arg.to_s }
+ arguments.each { |arg| options << arg.to_s }
return system('ssh',*options)
end
#