简体   繁体   English

如何将Rake任务添加到默认的Rake任务?

[英]How to add a Rake task to the default Rake task?

Somehow Rspec and Cucumber are making it into my default rake task (which is fine because I want them there). 不知怎的,Rspec和Cucumber正在将它变成我的默认rake任务(这很好,因为我想要它们)。 But I have tried adding additional tasks to the default task and it has no effect. 但我已尝试将其他任务添加到默认任务,但它没有任何效果。

What is the proper way to add tasks to the default rake task? 将任务添加到默认rake任务的正确方法是什么?

Typically your Rakefile will have something like this: 通常你的Rakefile会有这样的东西:

task :default => [:spec]

You just need to add more tasks into this list. 您只需要在此列表中添加更多任务。

The answer from davogenes is correct for non-namespaced rake tasks. davogenes的答案对于非命名空间的rake任务是正确的。

If you want to have a default task in namespaces you need to do the following 如果要在命名空间中具有默认任务,则需要执行以下操作

namespace :mynamespace do
  desc "This should be the default"
  task :mydefault do
    Do.something_by_default
  end

  desc "Another task in this namespace"
  task :other do
    Do.something
  end
end

desc "This is the default task of mynamespace"
task mynamespace: 'mynamespace:mydefault'

Then you can run rake mynamespace as well as rake mynamespace:other or rake mynamespace:mydefault . 然后你可以运行rake mynamespace以及rake mynamespace:otherrake mynamespace:mydefault

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM