#!/usr/bin/env ruby require "rubygems" require "rake" require "fezzik" # Required for using rake/remote-task with rake >= 0.9.x include Rake::DSL Fezzik.activated = true USAGE = < # Run deployment tasks on destination servers fez get # Download tasks to use in your project fez -T # Display all tasks EOF def print_usage_and_exit puts USAGE exit end def print_version_and_exit puts "Version #{Fezzik::VERSION}" exit end def display_tasks_and_exit 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 ") puts output.strip.empty? ? "(No Fezzik tasks with descriptions are defined.)" : output exit 0 end 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 Fezzik.color_string(" [new]", :green) + " #{task}" else puts Fezzik.color_string(" [fail]", :red) + " #{task}" end end exit 0 end def run_fezzik_tasks ENV["fezzik_destination"] = ARGV[0] Fezzik.init Rake.application.init Rake.application.load_rakefile set :domain, ENV["domain"].split(",") if ENV["domain"] 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 Fezzik.color_string("[fail]", :red) exit 1 end begin tasks = ARGV[1..-1] tasks.each do |task_with_params| task_name, params = Fezzik::Util.split_task_and_params(task_with_params) Rake::Task["fezzik:#{task_name}"].invoke(params) end puts Fezzik.color_string("[success]", :green) rescue SystemExit, Rake::CommandFailedError => e puts Fezzik.color_string("[fail]", :red) exit 1 rescue StandardError => e puts e.message puts e.backtrace puts Fezzik.color_string("[fail]", :red) fail end end case ARGV[0] when nil then abort USAGE when "-h", "--help" then print_usage_and_exit when "-v", "--version" then print_version_and_exit when "-T", "--tasks" then display_tasks_and_exit when "get" then download_tasks_and_exit else run_fezzik_tasks end