Rake 中命名空间的默认任务 [英] Default task for namespace in Rake
本文介绍了Rake 中命名空间的默认任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设如下:
namespace :my_tasks do
task :foo do
do_something
end
task :bar do
do_something_else
end
task :all => [:foo, :bar]
end
如何使 :all
成为默认任务,以便运行 rake my_tasks
将调用它(而不必调用 rake my_tasks:all
)?
How do I make :all
be the default task, so that running rake my_tasks
will call it (instead of having to call rake my_tasks:all
)?
推荐答案
像这样把它放在命名空间之外:
Place it outside the namespace like this:
namespace :my_tasks do
task :foo do
do_something
end
task :bar do
do_something_else
end
end
task :all => ["my_tasks:foo", "my_tasks:bar"]
另外...如果您的任务需要参数,则:
Also... if your tasks require arguments then:
namespace :my_tasks do
task :foo, :arg1, :arg2 do |t, args|
do_something
end
task :bar, :arg1, :arg2 do |t, args|
do_something_else
end
end
task :my_tasks, :arg1, :arg2 do |t, args|
Rake::Task["my_tasks:foo"].invoke( args.arg1, args.arg2 )
Rake::Task["my_tasks:bar"].invoke( args.arg1, args.arg2 )
end
请注意在第二个示例中如何将任务命名为与命名空间相同的名称,即my_tasks"
Notice how in the 2nd example you can call the task the same name as the namespace, ie 'my_tasks'
这篇关于Rake 中命名空间的默认任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文