#!/usr/bin/env ruby require "rubygems" require "rake" require "colorize" require "fezzik" # 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 Fezzik.activated = true def usage <<-EOF Version #{Fezzik::VERSION} fez # Run deployment tasks on destination servers fez get # 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.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 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 " [new]".green + " #{task}" else puts " [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 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 case ARGV[0] when nil, "-h" then print_usage_and_exit when "-T" then display_tasks_and_exit when "get" then download_tasks_and_exit else run_fezzik_tasks end