lib/middleman-deploy/commands.rb in middleman-deploy-0.1.1 vs lib/middleman-deploy/commands.rb in middleman-deploy-0.1.2
- old
+ new
@@ -1,13 +1,10 @@
require "middleman-core/cli"
require "middleman-deploy/extension"
require "middleman-deploy/pkg-info"
-PACKAGE = "#{Middleman::Deploy::PACKAGE}"
-VERSION = "#{Middleman::Deploy::VERSION}"
-
module Middleman
module Cli
# This class provides a "deploy" command for the middleman CLI.
class Deploy < Thor
@@ -50,14 +47,17 @@
extension in config.rb.
# To deploy the build directory to a remote host via rsync:
activate :deploy do |deploy|
deploy.method = :rsync
- # host, user, and path *must* be set
- deploy.user = "tvaughan"
+ # host and path *must* be set
deploy.host = "www.example.com"
deploy.path = "/srv/www/site"
+ # user is optional (no default)
+ deploy.user = "tvaughan"
+ # port is optional (default is 22)
+ deploy.port = 5309
# clean is optional (default is false)
deploy.clean = true
end
# To deploy to a remote branch via git (e.g. gh-pages on github):
@@ -110,12 +110,12 @@
print_usage_and_die "The deploy extension requires you to set a method."
end
case options.method
when :rsync
- if (!options.host || !options.user || !options.path)
- print_usage_and_die "The rsync deploy method requires host, user, and path to be set."
+ if (!options.host || !options.path)
+ print_usage_and_die "The rsync deploy method requires host and path to be set."
end
when :ftp, :sftp
if (!options.host || !options.user || !options.password || !options.path)
print_usage_and_die "The #{options.method} method requires host, user, password, and path to be set."
end
@@ -125,17 +125,22 @@
end
def deploy_rsync
host = self.deploy_options.host
port = self.deploy_options.port
- user = self.deploy_options.user
path = self.deploy_options.path
- puts "## Deploying via rsync to #{user}@#{host}:#{path} port=#{port}"
+ # Append "@" to user if provided.
+ user = self.deploy_options.user
+ user = "#{user}@" if user && !user.empty?
- command = "rsync -avze '" + "ssh -p #{port}" + "' #{self.inst.build_dir}/ #{user}@#{host}:#{path}"
+ dest_url = "#{user}#{host}:#{path}"
+ puts "## Deploying via rsync to #{dest_url} port=#{port}"
+
+ command = "rsync -avze '" + "ssh -p #{port}" + "' #{self.inst.build_dir}/ #{dest_url}"
+
if self.deploy_options.clean
command += " --delete"
end
run command
@@ -176,10 +181,10 @@
else
`git checkout -b #{branch}`
end
`git add -A`
- `git commit --allow-empty -am 'Automated commit at #{Time.now.utc} by #{PACKAGE} #{VERSION}'`
+ `git commit --allow-empty -am 'Automated commit at #{Time.now.utc} by #{Middleman::Deploy::PACKAGE} #{Middleman::Deploy::VERSION}'`
`git push -f origin #{branch}`
end
end
def deploy_ftp