lib/deployml/remote_shell.rb in deployml-0.3.0 vs lib/deployml/remote_shell.rb in deployml-0.4.0
- old
+ new
@@ -1,12 +1,25 @@
require 'deployml/shell'
+require 'addressable/uri'
+require 'shellwords'
+
module DeploYML
+ #
+ # Represents a shell running on a remote server.
+ #
class RemoteShell
include Shell
+ include Shellwords
+ # The URI of the remote shell
+ attr_reader :uri
+
+ # The history of the Remote Shell
+ attr_reader :history
+
#
# Initializes a remote shell session.
#
# @param [Addressable::URI, String] uri
# The URI of the host to connect to.
@@ -49,11 +62,11 @@
# Enqueues an `echo` command to be ran in the session.
#
# @param [String] message
# The message to echo.
#
- def each(message)
+ def echo(message)
run 'echo', message
end
#
# Enqueues a directory change for the session.
@@ -63,16 +76,15 @@
#
# @yield []
# If a block is given, then the directory will be changed back after
# the block has returned.
#
- def cd(path,&block)
+ def cd(path)
@history << ['cd', path]
- if block
- block.call() if block
-
+ if block_given?
+ yield
@history << ['cd', '-']
end
end
#
@@ -81,10 +93,12 @@
#
# @return [String]
# A single command string.
#
def join
- @history.map { |command| command.join(' ') }.join(' && ')
+ @history.map { |command|
+ command.map { |word| shellescape(word) }.join(' ')
+ }.join(' && ')
end
#
# Converts the URI to one compatible with SSH.
#