#!/usr/bin/env ruby require 'rubygems' require File.expand_path(File.dirname(__FILE__) + '/../lib/screwcap') require File.expand_path(File.dirname(__FILE__) + '/../lib/trollop') p = Trollop::Parser.new do opt :silent, "Be silent", :short => "s" opt :verbose, "Be verbose", :short => "v" opt :nocolor, "Do not color output" opt :debug, "Turn on debugger. Will print full stacktrace if an exeception was raised", :short => "d" opt :help, "Show this message", :short => "h" opt :tasks, "Display available tasks in recipe file", :short => "t" opt :setup_rails, "Setup a rails app to use screwcap", :short => "r" opt :dry_run, "Setup a rails app to use screwcap", :short => "n" version <<-EOF Screwcap #{Screwcap::VERSION} by Grant Ammons (grant@pipelinedeals.com) More info at http://gammons.github.com/screwcap EOF banner <<-EOF Usage: screwcap [options] file task_name [[task_name2], [task_name3], ...] Example: screwcap config/deploy.rb deploy_to_staging EOF end opts = Trollop::with_standard_exception_handling p do opts = p.parse ARGV if opts[:debug] == true require 'ruby-debug' Debugger.start end if opts[:tasks] == true or ARGV.size == 1 recipe_file = ARGV.shift deployer = TaskManager.new(opts.merge(:recipe_file => recipe_file)) $stdout << "\nTasks Available:\n" if deployer.__tasks.size > 0 deployer.__tasks.map {|t| t.__name }.each {|name| $stdout << " #{name}\n" } $stdout << "\nSequences Available:\n" if deployer.__sequences.size > 0 deployer.__sequences.map {|t| t.__name }.each {|name| $stdout << " #{name}\n" } $stdout << "\n" exit end if opts[:dry_run] == true recipe_file = ARGV.shift deployer = TaskManager.new(opts.merge(:recipe_file => recipe_file)) ARGV.map {|a| a.to_sym }.each do |tname| task = deployer.__tasks.find {|t| t.__name == tname } raise(Screwcap::TaskNotFound, "Could not find task named '#{tname}' in the recipe file.") if task.nil? $stdout << "\n*** BEGIN dry-run task #{task.__name}\n" task.__commands.each do |cmd| $stdout << " I: (dry-run): #{cmd[:command]}\n" end $stdout << "*** END dry-run task #{task.__name}\n" end exit end if opts[:setup_rails] == true TaskManager.new(:recipe_file => File.expand_path(File.dirname(__FILE__) + "/../recipes/setup_rails.rb")).run! :setup_rails $stdout << "\nYour rails app now has a sample recipe, ready for the editing, in config/screwcap/recipe.rb\n" $stdout << "Your recipes will be automatically available in rake. Screwcap uses the :remote namespace.\n" $stdout << "To see what recipes you can run, type 'rake -T remote'.\n" $stdout << "Please visit http://gammons.github.com/screwcap for help.\n" exit end recipe_file = ARGV.shift begin TaskManager.new(opts.merge(:recipe_file => recipe_file)).run! ARGV.map {|a| a.to_sym } rescue Exception => e raise e if opts[:debug] == true $stderr << e $stderr << "\n" end end