Create a file called rakefile
in the directory you want to run the task from.
This code will make it so that if you just type "rake" my_default_task will run:
task :default => my_default_task
task :my_default_task do
puts "Now I am doing the task that Tempus wants done when he/she types rake in the console."
end
task :my_not_default_task do
puts "This isn t the default task."
end
但是,如果你输入 rake my_not_default_task
,那么 my_default_task
就不会运行。 如果您想要它运行不管这里如何, 您可以做一件事 :
task :default => my_default_task
task :my_default_task do
puts "This is the default task"
end
task :my_not_default_task do
puts "This isn t the default task."
end
Rake::Task[ my_default_task ].invoke
此代码中最后一行确保我的_ default_task 运行, 即使您调用其它任务, 所以如果您输入 rake my_ not_ default_task
< 也会运行。
EDIT:
When you re working with rails you can put the tasks above in a file in the lib/tasks
folder with an extension of .rake
and rails will automagically run them when you do rake
Jason Seifer在rake 上有一个非常好的辅导。