它是由一個rake任務內可能獲得命名空間中的任務列表?一種編程式的「rake -T db」?是否有可能得到的命名空間中的所有可用的耙任務列表?
18
A
回答
16
1
更多詳細信息您可以使用grep命令這樣
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
11
正如你寫,用Rake.application.tasks你得到的所有任務。
但命名空間中,您可以選擇命名空間(任務mytest的:任務列表)的唯一任務
而且你可能會限制該任務命名空間(任務tasklist_mytest)。
require 'rake'
namespace :mytest do |ns|
task :foo do |t|
puts "You called task #{t}"
end
task :bar do |t|
puts "You called task #{t}"
end
desc 'Get tasks inside actual namespace'
task :tasklist do
puts 'All tasks of "mytest":'
puts ns.tasks #ns is defined as block-argument
end
end
desc 'Get all tasks'
task :tasklist do
puts 'All tasks:'
puts Rake.application.tasks
end
desc 'Get tasks outside the namespace'
task :tasklist_mytest do
puts 'All tasks of "mytest":'
Rake.application.in_namespace(:mytest){|x|
puts x.tasks
}
end
if $0 == __FILE__
Rake.application['tasklist'].invoke() #all tasks
Rake.application['mytest:tasklist'].invoke() #tasks of mytest
Rake.application['tasklist_mytest'].invoke() #tasks of mytest
end
相關問題
- 1. 是否有可能獲得已定義的命名空間的列表
- 2. 是否有可能顛倒c#命名空間的別名?
- 3. 是否有可能在VB.NET WinForms項目的子命名空間中有表單?
- 4. 它是否有可能改變一個dll的命名空間?
- 5. 是否有可能強制`round`在命名空間std中?
- 6. 獲取AppDomain中所有可用名稱空間的列表
- 7. 是否有可能獲得所有可能的網址?
- 8. 是否有可能在耙式任務上記錄sql查詢?
- 9. 是否有任何IDE能夠重命名PHP中的重構命名空間?
- 10. 是否有可能得到所有的提供的facebook頁面
- 11. 是否有可能在PHP中使用一個命名空間的變量?
- 12. 是否有可能將模板實例視爲命名空間?
- 13. 是否有可能通過命名空間找到類文件的位置?
- 14. 是否有可能獲得可以在Web服務中返回的所有值的列表
- 15. 是否可以在C++中查看命名空間的所有內容?
- 16. 是否有所有可能的PHP imap_last_error()消息的列表?
- 17. 是否有可能得到的Android
- 18. 如何獲得sqlite 3中給定表的所有列名的列表? (表可能是空的)
- 19. 是否有可能獲得java包中所有接口的列表?
- 20. 是否有可能得到的SonarQube常規規則列表
- 21. 是否有可能獲得ant scp任務的退出代碼?
- 22. 是否有可能獲得div中所有<input>的值?
- 23. 是否有Outlook MAPI命名空間的ID列表?
- 24. 是否有可能從javascript scriptdef任務中調用ant任務?
- 25. 是否有可能具有命名的角度配置功能?
- 26. 是否有可能更改實體的名稱空間(NDB)
- 27. 是否有可能得到使用JNLP
- 28. 是否有可能填補所有選項空間與色彩
- 29. 是否有SYSTEM_HANDLE_ENTRY.ObjectType的可能值列表?
- 30. 是否可以引用兩個命名空間相同的命名空間?
據我所看到的,沒有幫手的範圍內,尋找的東西,但我認爲,這應該是很容易:Rake.application.tasks.reject {|任務| task.scope =![:你,:範圍]} – phoet 2011-02-28 09:46:58
在我的情況(滑軌),但也有必要執行'AppName的:: Application.load_tasks'填充'Rake.application.tasks' – joshfindit 2016-08-19 13:57:51