Default task for namespace in Rake

2019-01-21 12:06发布

Given something like:

namespace :my_tasks do
  task :foo do
    do_something
  end

  task :bar do
    do_something_else
  end

  task :all => [:foo, :bar]
end

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)?

标签: ruby rake
7条回答
爷的心禁止访问
2楼-- · 2019-01-21 12:54

Based on Rocky's solution Default task for namespace in Rake

And this dexter's answer Is there a way to know the current rake task?

namespace :root do
  namespace :foo do
  end

  namespace :target do
    task :all do |task_all|
      Rake.application.in_namespace(task_all.scope.path) do |ns|
        ns.tasks.each { |task| task.invoke unless task.name == task_all.name } 
      end
    end

    task :one do
    end

    task :another do
    end
  end
end
查看更多
登录 后发表回答