Add Tap#contents methods.

This commit is contained in:
Markus Reiter 2018-06-20 20:35:24 +02:00
parent 7671606ddc
commit 785750ee63
2 changed files with 28 additions and 13 deletions

View File

@ -62,13 +62,11 @@ module Homebrew
if tap.installed? if tap.installed?
info += tap.pinned? ? "pinned" : "unpinned" info += tap.pinned? ? "pinned" : "unpinned"
info += ", private" if tap.private? info += ", private" if tap.private?
if (formula_count = tap.formula_files.size).positive? if (contents = tap.contents).empty?
info += ", #{Formatter.pluralize(formula_count, "formula")}" info += ", no commands/casks/formulae"
else
info += ", #{contents.join(", ")}"
end end
if (command_count = tap.command_files.size).positive?
info += ", #{Formatter.pluralize(command_count, "command")}"
end
info += ", no formulae/commands" if (formula_count + command_count).zero?
info += "\n#{tap.path} (#{tap.path.abv})" info += "\n#{tap.path} (#{tap.path.abv})"
info += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}" info += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}"
else else

View File

@ -284,9 +284,8 @@ class Tap
link_completions_and_manpages link_completions_and_manpages
casks = Formatter.pluralize(cask_files.count, "cask") formatted_contents = Formatter.enumeration(*contents)&.prepend(" ")
formulae = Formatter.pluralize(formula_files.count, "formula") puts "Tapped#{formatted_contents} (#{path.abv})." unless quiet
puts "Tapped #{formulae} and #{casks} (#{path.abv})." unless quiet
Descriptions.cache_formulae(formula_names) Descriptions.cache_formulae(formula_names)
return if options[:clone_target] return if options[:clone_target]
@ -315,8 +314,7 @@ class Tap
puts "Untapping #{name}..." puts "Untapping #{name}..."
abv = path.abv abv = path.abv
casks = Formatter.pluralize(cask_files.count, "cask") formatted_contents = Formatter.enumeration(*contents)&.prepend(" ")
formulae = Formatter.pluralize(formula_files.count, "formula")
unpin if pinned? unpin if pinned?
Descriptions.uncache_formulae(formula_names) Descriptions.uncache_formulae(formula_names)
@ -324,7 +322,7 @@ class Tap
Utils::Link.unlink_completions(path) Utils::Link.unlink_completions(path)
path.rmtree path.rmtree
path.parent.rmdir_if_possible path.parent.rmdir_if_possible
puts "Untapped #{formulae} and #{casks} (#{abv})." puts "Untapped#{formatted_contents} (#{abv})."
clear_cache clear_cache
end end
@ -348,6 +346,24 @@ class Tap
@cask_dir ||= path/"Casks" @cask_dir ||= path/"Casks"
end end
def contents
contents = []
if (command_count = command_files.count).positive?
contents << Formatter.pluralize(command_count, "command")
end
if (cask_count = cask_files.count).positive?
contents << Formatter.pluralize(cask_count, "cask")
end
if (formula_count = formula_files.count).positive?
contents << Formatter.pluralize(formula_count, "formula")
end
contents
end
# an array of all {Formula} files of this {Tap}. # an array of all {Formula} files of this {Tap}.
def formula_files def formula_files
@formula_files ||= if formula_dir.directory? @formula_files ||= if formula_dir.directory?
@ -432,7 +448,8 @@ class Tap
# an array of all commands files of this {Tap}. # an array of all commands files of this {Tap}.
def command_files def command_files
@command_files ||= Pathname.glob("#{path}/cmd/brew-*").select(&:executable?) @command_files ||= Pathname.glob("#{path}/cmd/brew{,cask}-*")
.select { |file| file.executable? || file.extname == ".rb" }
end end
# path to the pin record for this {Tap}. # path to the pin record for this {Tap}.