【问题标题】:How to add a Rake task to the default Rake task?如何将 Rake 任务添加到默认 Rake 任务?
【发布时间】:2013-05-12 05:34:42
【问题描述】:

不知何故,Rspec 和 Cucumber 正在将其纳入我的默认 rake 任务(这很好,因为我希望它们在那里)。但是我已经尝试在默认任务中添加额外的任务,但没有任何效果。

将任务添加到默认 rake 任务的正确方法是什么?

【问题讨论】:

    标签: ruby rake


    【解决方案1】:

    davogenes 的答案对于非命名空间的 rake 任务是正确的。

    如果您想在命名空间中有一个默认任务,您需要执行以下操作

    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'
    

    然后您可以运行rake mynamespace 以及rake mynamespace:otherrake mynamespace:mydefault

    【讨论】:

    • 您还可以从命名空间默认任务中删除“desc”行,这样它就不会出现在rake --tasks 中(只有 mynamespace 和 mynamespace:other 会出现在 --tasks然后命令)。如果你不这样做,两者都将出现在 --tasks 命令中,因此看起来是重复的。
    【解决方案2】:

    通常你的 Rakefile 会有这样的东西:

    task :default => [:spec]
    

    您只需在此列表中添加更多任务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-22
      • 2011-12-28
      • 2010-10-09
      • 1970-01-01
      • 2013-06-15
      • 2019-04-13
      • 2010-12-25
      • 1970-01-01
      相关资源
      最近更新 更多