diff --git a/lib/middleman-deploy.rb b/lib/middleman-deploy.rb index e86f469..78b96d4 100644 --- a/lib/middleman-deploy.rb +++ b/lib/middleman-deploy.rb @@ -1,5 +1,7 @@ require "middleman-core" +require "middleman-deploy/commands" + ::Middleman::Extensions.register(:deploy) do require "middleman-deploy/extension" ::Middleman::Deploy diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 118afb2..c9b6c42 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -1 +1,36 @@ require "middleman-core/cli" + +require "middleman-deploy/extension" + +module Middleman + module Cli + # This class provides a "deploy" command for the middleman CLI. + class Deploy < Thor + include Thor::Actions + + check_unknown_options! + + namespace :deploy + + # Tell Thor to exit with a nonzero exit code on failure + def self.exit_on_failure? + true + end + + desc "deploy", "Deploy to a remote host over rsync" + def deploy + shared_instance = ::Middleman::Application.server.inst + + # This only exists when the config.rb sets it! + if shared_instance.respond_to? :deploy + shared_instance.deploy(self) + else + raise Thor::Error.new "You need to activate the deploy extension in config.rb " + end + end + end + + # Alias "d" to "deploy" + Base.map({ "d" => "deploy" }) + end +end diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index fcd1724..44cd638 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -7,7 +7,9 @@ module Middleman class Options < Struct.new(:delete, :host, :port, :user, :path); end class << self - + def options + @@options + end def registered(app, options_hash={}, &block) options = Options.new(options_hash) yield options if block_given? @@ -15,6 +17,10 @@ module Middleman options.delete ||= false options.port ||= 22 + @@options = options + + app.send :include, Helpers + app.after_configuration do if (!options.host || !options.user || !options.path) raise <