Default task for namespace in Rake

前端 未结 8 1535
醉酒成梦
醉酒成梦 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-12 23:44

    Add the following task outside of the namespace:

    desc "Run all my tasks"
    task :my_tasks => ["my_tasks:all"]
    

    Keep in mind, that you can have a task with the same name as the namespace.

    And hier a bigger example, that shows, how you can make use of tasks, which have the same name as the namespace, even when nesting namespaces:

    namespace :job1 do
      task :do_something1 do
            puts "job1:do_something1"
        end
    
      task :do_something2 do
            puts "job1:do_something2"
        end
      task :all => [:do_something1, :do_something2]
    end
    
    desc "Job 1"
    task :job1 => ["job1:all"]
    
    # You do not need the "all"-task, but it might be handier to have one.
    namespace :job2 do
      task :do_something1 do
            puts "job2:do_something1"
        end
    
      task :do_something2 do
            puts "job2:do_something2"
        end
    end
    
    desc "Job 2"
    task :job2 => ["job2:do_something1", "job2:do_something2"]
    
    namespace :superjob do
        namespace :job1 do
            task :do_something1 do
                puts "superjob:job1:do_something1"
            end
    
            task :do_something2 do
                puts "superjob:job1:do_something2"
            end
        end
    
        desc "Job 1 in Superjob"
        task :job1 => ["job1:do_something1", "job1:do_something2"]
    
        namespace :job2 do
            task :do_something1 do
                puts "superjob:job2:do_something1"
            end
    
            task :do_something2 do
                puts "superjob:job2:do_something2"
            end
        end
    
        desc "Job 2 in Superjob"
        task :job2 => ["job2:do_something1", "job2:do_something2"]
    end
    
    desc "My Super Job"
    task :superjob => ["superjob:job1", "superjob:job2"]
    
    # Do them all just by calling "$ rake"
    task :default => [:job1, :job2, :superjob]
    

    Just copy it and try it out.

提交回复
热议问题