Merge pull request #4357 from reitermarkus/tapped-cask-count

Show tapped casks.
This commit is contained in:
Markus Reiter 2018-07-02 20:46:33 +02:00 committed by GitHub
commit cbc3184436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 12 deletions

View File

@ -62,13 +62,11 @@ module Homebrew
if tap.installed?
info += tap.pinned? ? "pinned" : "unpinned"
info += ", private" if tap.private?
if (formula_count = tap.formula_files.size).positive?
info += ", #{Formatter.pluralize(formula_count, "formula")}"
info += if (contents = tap.contents).empty?
", no commands/casks/formulae"
else
", #{contents.join(", ")}"
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 += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}"
else

View File

@ -284,8 +284,8 @@ class Tap
link_completions_and_manpages
formula_count = formula_files.size
puts "Tapped #{Formatter.pluralize(formula_count, "formula")} (#{path.abv})" unless quiet
formatted_contents = Formatter.comma_and(*contents)&.prepend(" ")
puts "Tapped#{formatted_contents} (#{path.abv})." unless quiet
Descriptions.cache_formulae(formula_names)
return if options[:clone_target]
@ -311,15 +311,18 @@ class Tap
require "descriptions"
raise TapUnavailableError, name unless installed?
puts "Untapping #{name}... (#{path.abv})"
puts "Untapping #{name}..."
abv = path.abv
formatted_contents = Formatter.comma_and(*contents)&.prepend(" ")
unpin if pinned?
formula_count = formula_files.size
Descriptions.uncache_formulae(formula_names)
Utils::Link.unlink_manpages(path)
Utils::Link.unlink_completions(path)
path.rmtree
path.parent.rmdir_if_possible
puts "Untapped #{Formatter.pluralize(formula_count, "formula")}"
puts "Untapped#{formatted_contents} (#{abv})."
clear_cache
end
@ -343,6 +346,24 @@ class Tap
@cask_dir ||= path/"Casks"
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}.
def formula_files
@formula_files ||= if formula_dir.directory?
@ -427,7 +448,8 @@ class Tap
# an array of all commands files of this {Tap}.
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
# path to the pin record for this {Tap}.

View File

@ -76,4 +76,22 @@ describe Formatter do
expect(described_class.pluralize(2, "new formula")).to eq("2 new formulae")
end
end
describe "::comma_and" do
it "returns nil if given no arguments" do
expect(described_class.comma_and).to be nil
end
it "returns the input as string if there is only one argument" do
expect(described_class.comma_and(1)).to eq("1")
end
it "concatenates two items with “and”" do
expect(described_class.comma_and(1, 2)).to eq("1 and 2")
end
it "concatenates all items with a comma and appends the last with “and”" do
expect(described_class.comma_and(1, 2, 3)).to eq("1, 2 and 3")
end
end
end

View File

@ -108,4 +108,14 @@ module Formatter
show_count ? "#{count} #{words}" : words
end
def comma_and(*items)
# TODO: Remove when RuboCop 0.57.3 is released.
# False positive has been fixed and merged, but is not yet in a
# stable release: https://github.com/rubocop-hq/rubocop/pull/6038
*items, last = items.map(&:to_s) # rubocop:disable Lint/ShadowedArgument
return last if items.empty?
"#{items.join(", ")} and #{last}"
end
end