Default task for namespace in Rake

前端 未结 8 1525
醉酒成梦
醉酒成梦 2020-12-12 23:05

Given something like:

namespace :my_tasks do
  task :foo do
    do_something
  end

  task :bar do
    do_something_else
  end

  task :all => [:foo, :bar         


        
8条回答
  •  爱一瞬间的悲伤
    2020-12-13 00:06

    Not very intuitive, but you can have a namespace and a task that have the same name, and that effectively gives you what you want. For instance

    namespace :my_task do
      task :foo do
        do_foo
      end
      task :bar do
        do_bar
      end
    end
    
    task :my_task do
      Rake::Task['my_task:foo'].invoke
      Rake::Task['my_task:bar'].invoke
    end
    

    Now you can run commands like,

    rake my_task:foo
    

    and

    rake my_task
    

提交回复
热议问题