Skip to content

Commit

Permalink
desc: print short name unless multiple formulae have the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
jawshooah authored and bfontaine committed Apr 16, 2016
1 parent a8be17d commit abff8a0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Library/Homebrew/descriptions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "set"
require "formula"
require "formula_versions"

Expand Down Expand Up @@ -123,9 +124,22 @@ def initialize(descriptions)
# print them.
def print
blank = "#{Tty.yellow}[no description]#{Tty.reset}"
@descriptions.keys.sort.each do |name|
description = @descriptions[name] || blank
puts "#{Tty.white}#{name}:#{Tty.reset} #{description}"
@descriptions.keys.sort.each do |full_name|
short_name = short_names[full_name]
printed_name = short_name_counts[short_name] == 1 ? short_name : full_name
description = @descriptions[full_name] || blank
puts "#{Tty.white}#{printed_name}:#{Tty.reset} #{description}"
end
end

private

def short_names
@short_names ||= Hash[@descriptions.keys.map { |k| [k, k.split("/").last] }]
end

def short_name_counts
@short_name_counts ||=
short_names.values.reduce(Hash.new(0)) { |counts, name| counts[name] += 1; counts }
end
end

0 comments on commit abff8a0

Please sign in to comment.