bin/fez in fezzik-0.5.2 vs bin/fez in fezzik-0.6.0

- old
+ new

@@ -1,52 +1,88 @@ #!/usr/bin/env ruby require "rubygems" require "rake" -require "rake/remote_task" -require "fezzik" require "colorize" +require "fezzik" -# Include everything in config/recipes -Dir[File.join(Dir.pwd, 'config/recipes/**/*.rb')].sort.each { |lib| require lib } +# TODO: Add a handy "fez init" command to set up a basic deployable directory structure +# TODO: Think about how to do domain overrides better +# TODO: Add Fezzik::DSL so you can say env or destination instead of Fezzik.env, Fezzik.destination def usage <<-EOF +Version #{Fezzik::VERSION} fez <destination> <tasks> # Run deployment tasks on destination servers -fez get <recipes> # Download recipes to use in your project +fez get <tasks> # Download tasks to use in your project fez -T # Display all tasks EOF end +def print_usage_and_exit + puts usage + exit 1 +end + def display_tasks_and_exit - Rake.application.options.show_task_pattern = // - output = capture_output { Rake.application.display_tasks_and_comments } + Rake.application.init + Rake.application.load_rakefile + Rake.application.options.show_task_pattern = /^fezzik:/ + output = Fezzik::Util.capture_output { Rake.application.display_tasks_and_comments } output.gsub!(/^rake fezzik:/, "fez <destination> ") puts output exit 0 end -RECIPE_URL = "https://raw.github.com/dmacdougall/fezzik/master/recipes" -def download_recipes_and_exit - system("mkdir -p config/recipes") - ARGV[1..-1].each do |recipe| - recipe += ".rb" unless recipe[-3..-1] == ".rb" - system("curl -f #{RECIPE_URL}/#{recipe} -o config/recipes/#{recipe} > /dev/null 2>&1") +TASKS_URL = "https://raw.github.com/dmacdougall/fezzik/master/tasks" +def download_tasks_and_exit + ARGV[1..-1].each do |task| + task += ".rake" unless task =~ /\.rake$/ + system("curl -f #{TASKS_URL}/#{task} -o #{task} > /dev/null 2>&1") if $? == 0 - puts " [new]".green + " config/recipes/#{recipe}" + puts " [new]".green + " #{task}" else - puts " [fail]".red + " config/recipes/#{recipe}" + puts " [fail]".red + " #{task}" end end exit 0 end -if ARGV.size == 0 - puts usage - exit 1 -elsif ARGV[0] == "-T" - display_tasks_and_exit -elsif ARGV[0] == "get" - download_recipes_and_exit +def run_fezzik_tasks + ENV["fezzik_destination"] = ARGV[0] + Fezzik.init + Rake.application.init + Rake.application.load_rakefile + begin + host_list = Array(domain).join("\n ") + puts "Targeting hosts:" + puts " #{host_list}" + rescue Rake::ConfigurationError => e + puts "Invalid destination: #{Fezzik.target_destination}" + puts "Make sure this destination is configured and includes `set :domain, \"yourdomain.com\"`" + puts "[fail]".red + exit 1 + end + begin + tasks = ARGV[1..-1] + tasks.each do |task_with_params| + task, params = Fezzik::Util.split_task_and_params(task_with_params) + Rake::Task["fezzik:#{task}"].invoke(params) + end + puts "[success]".green + rescue SystemExit, Rake::CommandFailedError => e + puts "[fail]".red + exit 1 + rescue StandardError => e + puts e.message + puts e.backtrace + puts "[fail]".red + fail + end end -Rake.application["fezzik:run"].invoke +case ARGV[0] +when nil then print_usage_and_exit +when "-T" then display_tasks_and_exit +when "get" then download_tasks_and_exit +else run_fezzik_tasks +end