From 46e1b364cfccb175e4244164958bac80ece54440 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 23 Dec 2006 16:09:27 +0000 Subject: [PATCH] Added support for ~/.caprc and -x/-c switches. git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@5774 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- CHANGELOG | 2 ++ lib/capistrano/cli.rb | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 9b1a6b62..9d28762a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added support for ~/.caprc, also -x and -c switches. + * Updated migrate action to use db:migrate task in Rails instead of the deprecated migrate task [DHH] * Allow SSH user and port to be encoded in the hostname strings [Ezra Zygmuntowicz] diff --git a/lib/capistrano/cli.rb b/lib/capistrano/cli.rb index f43fe3d2..81adbf49 100644 --- a/lib/capistrano/cli.rb +++ b/lib/capistrano/cli.rb @@ -96,7 +96,7 @@ module Capistrano def initialize(args = ARGV) @args = args @options = { :recipes => [], :actions => [], :vars => {}, - :pre_vars => {} } + :pre_vars => {}, :dotfile => default_dotfile } OptionParser.new do |opts| opts.banner = "Usage: #{$0} [options] [args]" @@ -110,6 +110,14 @@ module Capistrano "be specified, and are loaded in the given order." ) { |value| @options[:actions] << value } + opts.on("-c", "--caprc FILE", + "Specify an alternate personal config file to load.", + "(Default: #{@options[:dotfile]})" + ) do |value| + abort "The config file `#{value}' does not exist" unless File.exist?(value) + @options[:dotfile] = value + end + opts.on("-f", "--file FILE", "A recipe file to load. Multiple recipes may", "be specified, and are loaded in the given order." @@ -147,6 +155,12 @@ module Capistrano @options[:pre_vars][name.to_sym] = value end + opts.on("-x", "--skip-config", + "Disables the loading of the default personal config", + "file. Specifying -C after this option will reenable", + "it. (Default: config file is loaded)" + ) { @options[:dotfile] = nil } + opts.separator "" opts.separator "Framework Integration Options --------" opts.separator "" @@ -245,6 +259,7 @@ DETAIL config.set :pretend, options[:pretend] options[:pre_vars].each { |name, value| config.set(name, value) } + config.load(@options[:dotfile]) if @options[:dotfile] && File.exist?(@options[:dotfile]) # load the standard recipe definition config.load "standard" @@ -288,6 +303,16 @@ DETAIL end end + def default_dotfile + File.join(home_directory, ".caprc") + end + + def home_directory + ENV["HOME"] || + (ENV["HOMEPATH"] && "#{ENV["HOMEDRIVE"]}#{ENV["HOMEPATH"]}") || + "/" + end + def look_for_default_recipe_file! DEFAULT_RECIPES.each do |file| if File.exist?(file)