tags:

views:

33

answers:

2

Is it possible from within a rake task to get a list of tasks in a namespace? A sort of programatic 'rake -T db' ?

A: 

I've found out the answer:

tasks = Rake.application.tasks

This will return an array of Rake::Task objects that can be examined. Further details at http://rake.rubyforge.org/

stephenr
A: 

You can use the grep command like this

desc 'Test'
task :test do
    # You can change db: by any other namespaces
    result = %x[rake -T | sed -n '/db:/{/grep/!p;}' | awk '{print$2}'] 
    result.each_line do |t|
        puts t # Where t is your task name
    end
end
garno