Is it possible to get a list of all available rake tasks in a namespace?

后端 未结 3 568
名媛妹妹
名媛妹妹 2020-12-31 02:13

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

3条回答
  •  天涯浪人
    2020-12-31 02:24

    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
    

提交回复
热议问题