Skip to content

Instantly share code, notes, and snippets.

@tonini
Last active December 19, 2015 08:49
Show Gist options
  • Save tonini/5928130 to your computer and use it in GitHub Desktop.
Save tonini/5928130 to your computer and use it in GitHub Desktop.
# Display the tasks and comments.
# rake -D => :describe
# rake -T => :tasks
def display_tasks_and_comments
displayable_tasks = tasks.select { |t|
(options.show_all_tasks || t.comment) &&
t.name =~ options.show_task_pattern
}
case options.show_tasks
when :tasks
width = displayable_tasks.map { |t| t.name_with_args.length }.max || 10
if truncate_output?
max_column = terminal_width - name.size - width - 7
else
max_column = nil
end
displayable_tasks.each do |t|
printf("#{name} %-#{width}s # %s\n",
t.name_with_args,
max_column ? truncate(t.comment, max_column) : t.comment)
end
when :describe
displayable_tasks.each do |t|
puts "#{name} #{t.name_with_args}"
comment = t.full_comment || ""
comment.split("\n").each do |line|
puts " #{line}"
end
puts
end
when :lines
displayable_tasks.each do |t|
t.locations.each do |loc|
printf "#{name} %-30s %s\n", t.name_with_args, loc
end
end
else
fail "Unknown show task mode: '#{options.show_tasks}'"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment