From 2aa7597e70d8aa5bd529494884646797ea547cb0 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 19 Jun 2018 17:59:25 +0200 Subject: [PATCH 1/7] Show tapped casks. --- Library/Homebrew/tap.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index a6f7c4044f..3816137038 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -284,8 +284,9 @@ class Tap link_completions_and_manpages - formula_count = formula_files.size - puts "Tapped #{Formatter.pluralize(formula_count, "formula")} (#{path.abv})" unless quiet + casks = Formatter.pluralize(cask_files.count, "cask") + formulae = Formatter.pluralize(formula_files.count, "formula") + puts "Tapped #{formulae} and #{casks} (#{path.abv})." unless quiet Descriptions.cache_formulae(formula_names) return if options[:clone_target] @@ -311,15 +312,19 @@ class Tap require "descriptions" raise TapUnavailableError, name unless installed? - puts "Untapping #{name}... (#{path.abv})" + puts "Untapping #{name}..." + + abv = path.abv + casks = Formatter.pluralize(cask_files.count, "cask") + formulae = Formatter.pluralize(formula_files.count, "formula") + 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 #{formulae} and #{casks} (#{abv})." clear_cache end From 7671606ddcd0e16f1b31dd8e71635913771ed127 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 20 Jun 2018 20:32:28 +0200 Subject: [PATCH 2/7] Add `Formatter::enumeration`. --- Library/Homebrew/test/formatter_spec.rb | 18 ++++++++++++++++++ Library/Homebrew/utils/formatter.rb | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/Library/Homebrew/test/formatter_spec.rb b/Library/Homebrew/test/formatter_spec.rb index 14c63b8c3a..8d5ca8f41a 100644 --- a/Library/Homebrew/test/formatter_spec.rb +++ b/Library/Homebrew/test/formatter_spec.rb @@ -76,4 +76,22 @@ describe Formatter do expect(described_class.pluralize(2, "new formula")).to eq("2 new formulae") end end + + describe "::enumeration" do + it "returns nil if given no arguments" do + expect(described_class.enumeration).to be nil + end + + it "returns the input as string if there is only one argument" do + expect(described_class.enumeration(1)).to eq("1") + end + + it "concatenates two items with “and”" do + expect(described_class.enumeration(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.enumeration(1, 2, 3)).to eq("1, 2 and 3") + end + end end diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index ec144bf2f8..e6bdf6f034 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -108,4 +108,11 @@ module Formatter show_count ? "#{count} #{words}" : words end + + def enumeration(*items) + *items, last = items.map(&:to_s) + return last if items.empty? + + "#{items.join(", ")} and #{last}" + end end From 785750ee6364b14e47dfac352372cb51a83ee9c9 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 20 Jun 2018 20:35:24 +0200 Subject: [PATCH 3/7] Add `Tap#contents` methods. --- Library/Homebrew/cmd/tap-info.rb | 10 ++++------ Library/Homebrew/tap.rb | 31 ++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index b2d9ee5088..51e79b3de0 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -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")}" + if (contents = tap.contents).empty? + info += ", no commands/casks/formulae" + else + info += ", #{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 diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 3816137038..83eb197c32 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -284,9 +284,8 @@ class Tap link_completions_and_manpages - casks = Formatter.pluralize(cask_files.count, "cask") - formulae = Formatter.pluralize(formula_files.count, "formula") - puts "Tapped #{formulae} and #{casks} (#{path.abv})." unless quiet + formatted_contents = Formatter.enumeration(*contents)&.prepend(" ") + puts "Tapped#{formatted_contents} (#{path.abv})." unless quiet Descriptions.cache_formulae(formula_names) return if options[:clone_target] @@ -315,8 +314,7 @@ class Tap puts "Untapping #{name}..." abv = path.abv - casks = Formatter.pluralize(cask_files.count, "cask") - formulae = Formatter.pluralize(formula_files.count, "formula") + formatted_contents = Formatter.enumeration(*contents)&.prepend(" ") unpin if pinned? Descriptions.uncache_formulae(formula_names) @@ -324,7 +322,7 @@ class Tap Utils::Link.unlink_completions(path) path.rmtree path.parent.rmdir_if_possible - puts "Untapped #{formulae} and #{casks} (#{abv})." + puts "Untapped#{formatted_contents} (#{abv})." clear_cache end @@ -348,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? @@ -432,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}. From c6c1eacc18de6ad9580aeb43d4f2d90f9ad4c5bb Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 1 Jul 2018 01:35:47 +0200 Subject: [PATCH 4/7] Rename `enumeration` to `comma_and`. --- Library/Homebrew/tap.rb | 4 ++-- Library/Homebrew/test/formatter_spec.rb | 10 +++++----- Library/Homebrew/utils/formatter.rb | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 83eb197c32..5f7d691bff 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -284,7 +284,7 @@ class Tap link_completions_and_manpages - formatted_contents = Formatter.enumeration(*contents)&.prepend(" ") + formatted_contents = Formatter.comma_and(*contents)&.prepend(" ") puts "Tapped#{formatted_contents} (#{path.abv})." unless quiet Descriptions.cache_formulae(formula_names) @@ -314,7 +314,7 @@ class Tap puts "Untapping #{name}..." abv = path.abv - formatted_contents = Formatter.enumeration(*contents)&.prepend(" ") + formatted_contents = Formatter.comma_and(*contents)&.prepend(" ") unpin if pinned? Descriptions.uncache_formulae(formula_names) diff --git a/Library/Homebrew/test/formatter_spec.rb b/Library/Homebrew/test/formatter_spec.rb index 8d5ca8f41a..1c97bf6f8f 100644 --- a/Library/Homebrew/test/formatter_spec.rb +++ b/Library/Homebrew/test/formatter_spec.rb @@ -77,21 +77,21 @@ describe Formatter do end end - describe "::enumeration" do + describe "::comma_and" do it "returns nil if given no arguments" do - expect(described_class.enumeration).to be nil + 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.enumeration(1)).to eq("1") + expect(described_class.comma_and(1)).to eq("1") end it "concatenates two items with “and”" do - expect(described_class.enumeration(1, 2)).to eq("1 and 2") + 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.enumeration(1, 2, 3)).to eq("1, 2 and 3") + expect(described_class.comma_and(1, 2, 3)).to eq("1, 2 and 3") end end end diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index e6bdf6f034..4db1abf54d 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -109,7 +109,7 @@ module Formatter show_count ? "#{count} #{words}" : words end - def enumeration(*items) + def comma_and(*items) *items, last = items.map(&:to_s) return last if items.empty? From 71a79e7e040202c543e54198bc91539c0b7abc01 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 1 Jul 2018 01:40:58 +0200 Subject: [PATCH 5/7] Ignore false RuboCop positive. --- Library/Homebrew/utils/formatter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 4db1abf54d..35dc881837 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -110,7 +110,7 @@ module Formatter end def comma_and(*items) - *items, last = items.map(&:to_s) + *items, last = items.map(&:to_s) # rubocop:disable Lint/ShadowedArgument, TODO: Remove when RuboCop 0.57.3 is released. return last if items.empty? "#{items.join(", ")} and #{last}" From 9d79cf1e9de286d113e999f69c063577f33a8fbd Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 1 Jul 2018 18:45:52 +0200 Subject: [PATCH 6/7] Reference RuboCop issue. --- Library/Homebrew/utils/formatter.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 35dc881837..36542d7389 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -110,7 +110,10 @@ module Formatter end def comma_and(*items) - *items, last = items.map(&:to_s) # rubocop:disable Lint/ShadowedArgument, TODO: Remove when RuboCop 0.57.3 is released. + # 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}" From a15b016ea64d293a63bdc351d250b631580fbb9e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 2 Jul 2018 00:11:42 +0200 Subject: [PATCH 7/7] Use `if` for assignment. --- Library/Homebrew/cmd/tap-info.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index 51e79b3de0..0f63082a10 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -62,10 +62,10 @@ module Homebrew if tap.installed? info += tap.pinned? ? "pinned" : "unpinned" info += ", private" if tap.private? - if (contents = tap.contents).empty? - info += ", no commands/casks/formulae" + info += if (contents = tap.contents).empty? + ", no commands/casks/formulae" else - info += ", #{contents.join(", ")}" + ", #{contents.join(", ")}" end info += "\n#{tap.path} (#{tap.path.abv})" info += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}"