Skip to content

Commit

Permalink
Reworked task :list (-T) output; now shows global options, better layout
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien committed Oct 11, 2008
1 parent d795d20 commit 34682ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/thor/options.rb
Expand Up @@ -176,6 +176,8 @@ def formatted_usage
end
end.join(" ")
end

alias :to_s :formatted_usage

private

Expand Down
33 changes: 23 additions & 10 deletions lib/thor/runner.rb
Expand Up @@ -200,9 +200,6 @@ def display_klasses(with_modules = false, klasses = Thor.subclasses)
puts
end

puts "Tasks"
puts "-----"

# Calculate the largest base class name
max_base = klasses.max do |x,y|
Thor::Util.constant_to_thor_path(x.name).size <=> Thor::Util.constant_to_thor_path(y.name).size
Expand All @@ -214,16 +211,32 @@ def display_klasses(with_modules = false, klasses = Thor.subclasses)
end

max_left = max_left_item.maxima.usage + max_left_item.maxima.opt

klasses.each {|k| display_tasks(k, max_base, max_left)}

unless klasses.empty?
puts # add some spacing
klasses.each { |k| display_tasks(k, max_base, max_left); }
else
puts "\033[1;34mNo Thor tasks available\033[0m"
end
end

def display_tasks(klass, max_base, max_left)
base = Thor::Util.constant_to_thor_path(klass.name)
klass.tasks.each true do |name, task|
format_string = "%-#{max_left + max_base + 5}s"
print format_string % task.formatted_usage(true)
puts task.description
if klass.tasks.values.length > 1
base = Thor::Util.constant_to_thor_path(klass.name)

puts "\033[1;34m#{base}\033[0m"
puts "-" * base.length

unless klass.opts.empty?
puts "global options: #{Options.new(klass.opts)}\n\n"
end

klass.tasks.each true do |name, task|
format_string = "%-#{max_left + max_base + 5}s"
print format_string % task.formatted_usage(true)
puts task.description
end
puts # add some spacing
end
end

Expand Down

0 comments on commit 34682ae

Please sign in to comment.