lib/r10k/cli/environment/deploy.rb in r10k-0.0.1rc1 vs lib/r10k/cli/environment/deploy.rb in r10k-0.0.1

- old
+ new

@@ -1,44 +1,46 @@ require 'r10k/cli/environment' require 'r10k/deployment' +require 'r10k/action' + require 'cri' +require 'middleware' -require 'fileutils' - module R10K::CLI::Environment module Deploy def self.command @cmd ||= Cri::Command.define do name 'deploy' - usage 'deploy' + usage 'deploy <environment> <...>' summary 'Deploy an environment' flag :r, :recurse, 'Recursively update submodules' + flag :u, :update, "Enable or disable cache updating" - required :u, :update, "Enable or disable cache updating" - run do |opts, args, cmd| deployment = R10K::Deployment.instance env_list = deployment.environments - update_cache = (defined? opts[:update]) ? (opts[:update] == 'true') : false - - if opts[:environment] - environments = env_list.select {|env| env.name == opts[:environment]} + if not args.empty? + environments = env_list.select {|env| args.include? env.name } else environments = env_list end - environments.each do |env| - FileUtils.mkdir_p env.full_path - env.sync! :update_cache => update_cache - - if opts[:recurse] - env.modules.each do |mod| - mod.sync! :update_cache => update_cache - end + stack = Middleware::Builder.new do + environments.each do |env| + use R10K::Action::Environment::Deploy, env end end + + # Prepare middleware environment + stack_env = { + :update_cache => opts[:update], + :recurse => opts[:recurse], + :trace => opts[:trace], + } + + stack.call(stack_env) end end end end self.command.add_command(Deploy.command)