Guest User

Untitled

a guest
Jun 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. # a capistrano task to list tasks by role.
  2. namespace :list do
  3. desc "list tasks by role"
  4. task :by_role do
  5. tasks = top.task_list(:all)
  6.  
  7. set(:verbose, false) unless exists?(:verbose)
  8. unless verbose
  9. tasks = tasks.reject { |t| t.description.empty? || t.description =~ /^\[internal\]/ }
  10. end
  11.  
  12. role_tasks = {}
  13. tasks.each do |task|
  14. role_tasks[task.options[:roles]] ||= []
  15. role_tasks[task.options[:roles]] << task
  16. end
  17.  
  18. longest = tasks.map { |task| task.fully_qualified_name.length }.max
  19. max_length = longest + 10
  20.  
  21. role_tasks.keys.sort{|a,b| a.to_s <=> b.to_s}.each do |role|
  22. puts role
  23. role_tasks[role].each do |task|
  24. puts "\t%-#{longest}s # %s" % [task.fully_qualified_name, (task.desc.nil?) ? "" : task.desc[0..100].gsub(/\n/,' ').squeeze(' ')+"..."]
  25. end
  26. puts "\n"
  27. end
  28.  
  29. end
  30. end
Add Comment
Please, Sign In to add comment