Rake main application object. When invoking
rake from the command line, a RakeApp object is created and run.
Create a RakeApp object.
# File minirake, line 329
def initialize
@rakefile = nil
@nosearch = false
end
Return a list of the command line options supported by the program.
# File minirake, line 378
def command_line_options
OPTIONS.collect { |lst| lst[0..-2] }
end
Display the tasks and dependencies.
# File minirake, line 369
def display_tasks
MiniRake::Task.tasks.each do |t|
puts "#{t.class} #{t.name}"
t.prerequisites.each { |pre| puts " #{pre}" }
end
end
Do the option defined by opt and value.
# File minirake, line 383
def do_option(opt, value)
case opt
when '--dry-run'
$dryrun = true
$trace = true
when '--help'
help
exit
when '--libdir'
$:.push(value)
when '--nosearch'
@nosearch = true
when '--quiet'
$verbose = false
when '--rakefile'
RAKEFILES.clear
RAKEFILES << value
when '--require'
require value
when '--tasks'
$show_tasks = true
when '--trace'
$trace = true
when '--usage'
usage
exit
when '--verbose'
$verbose = true
when '--version'
puts "rake, version #{RAKEVERSION}"
exit
else
fail "Unknown option: #{opt}"
end
end
Read and handle the command line options.
# File minirake, line 420
def handle_options
$verbose = false
opts = GetoptLong.new(*command_line_options)
opts.each { |opt, value| do_option(opt, value) }
end
True if one of the files in RAKEFILES is in the current directory. If a match is found, it is copied into @rakefile.
# File minirake, line 336
def have_rakefile
RAKEFILES.each do |fn|
if File.exist?(fn)
@rakefile = fn
return true
end
end
return false
end
Display the rake command line help.
# File minirake, line 352
def help
usage
puts
puts "Options are ..."
puts
OPTIONS.sort.each do |long, short, mode, desc|
if mode == GetoptLong::REQUIRED_ARGUMENT
if desc =~ /\b([A-Z]{2,})\b/
long = long + "=#{$1}"
end
end
printf " %-20s (%s)\n", long, short
printf " %s\n", desc
end
end
Run the rake application.
# File minirake, line 427
def run
handle_options
begin
here = Dir.pwd
while ! have_rakefile
Dir.chdir("..")
if Dir.pwd == here || @nosearch
fail "No Rakefile found (looking for: #{RAKEFILES.join(', ')})"
end
here = Dir.pwd
end
tasks = []
ARGV.each do |task_name|
if /^(\w+)=(.*)/.match(task_name)
ENV[$1] = $2
else
tasks << task_name
end
end
puts "(in #{Dir.pwd})"
$rakefile = @rakefile
load @rakefile
if $show_tasks
display_tasks
else
tasks.push("default") if tasks.size == 0
tasks.each do |task_name|
MiniRake::Task[task_name].invoke
end
end
rescue Exception => ex
puts "rake aborted!"
puts ex.message
if $trace
puts ex.backtrace.join("\n")
else
puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
end
exit 1
end
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.