# Basically, I just need the following code integrated so that we can optionally pass RakeMate
# some parameters (rather than calling it directly and assuming that the current file is active)
#
# It would also be nice if we could use my method of inheriting the PATH from the environment so
# that Rails users wouldn't have to set TM_RAKE.
#
# Here are two sample calls to my rake_helper (aka, my version of RakeMate):
#
# == 1. Migrate to Current ==
# RUBYLIB="$TM_BUNDLE_SUPPORT/lib:$RUBYLIB"
# "${TM_RUBY:=ruby}" -- "${TM_BUNDLE_SUPPORT}/bin/rake_helper.rb" -t db:migrate -
#
# == 2. Migrate to Version... ==
# RUBYLIB="$TM_BUNDLE_SUPPORT/lib:$RUBYLIB"
#
# Find the current version number from the schema.rb file
# export CURRENT=`grep 'Schema\.define' "$TM_PROJECT_DIRECTORY/db/schema.rb" | \
# ruby -e 'print $stdin.read.scan(/\d+/).first'`
#
# "${TM_RUBY:=ruby}" -- "${TM_BUNDLE_SUPPORT}/bin/rake_helper.rb" db:migrate -q \
# "Migrate to which version? (Current version: $CURRENT)" -v VERSION
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: rake_helper.rb [options]"
opts.separator ""
opts.separator "Rake helper options:"
opts.on("-t", "--task [RAKE TASK]", "The Rake task to perform.") do |task|
options[:task] = task
end
opts.on("-q", "--question [QUESTION TEXT]", "Ask a question before running rake.") do |question|
options[:question] = question
end
opts.on("-a", "--answer [ANSWER TEXT]", "Default answer for the question.") do |answer|
options[:answer] = answer
end
opts.on("-v", "--variable [VARIABLE]", "Variable to assign the ANSWER to.") do |variable|
options[:variable] = variable
end
opts.on("-w", "--window-title [TITLE TEXT]", "Title of HTML window.") do |title|
options[:window_title] = title
end
opts.on("-p", "--pop-up-title [TITLE TEXT]", "Title of pop-up window.") do |title|
options[:pop_up_title] = title
end
end.parse!
if options[:question]
unless options[:answer] = TextMate.input(options[:question], options[:answer] || "", :title => options[:title] || "Rake")
TextMate.exit_discard
end
end
command = "rake #{task}"
command += " #{options[:variable]}=#{options[:answer]}" if options[:variable] && options[:answer]