From d305784c37c876d31e15d3baa842f0aa80f2f35f Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Fri, 10 Mar 2017 22:46:28 -0800 Subject: Added highlighting of installed casks to cask search --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 5 +++-- Library/Homebrew/cask/lib/hbc/utils.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 3f73fcd2e..a054358db 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -39,7 +39,7 @@ module Hbc end if exact_match ohai "Exact match" - puts exact_match + puts highlight_installed exact_match end return if partial_matches.empty? @@ -49,7 +49,8 @@ module Hbc else ohai "Partial matches" end - puts Formatter.columns(partial_matches) + highlighted = partial_matches.map { |match| highlight_installed match } + puts Formatter.columns(highlighted) end def self.help diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index ef3e5eda3..ef00104f9 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -36,6 +36,14 @@ def odebug(title, *sput) puts sput unless sput.empty? end +def highlight_installed(token) + cask = Hbc.load(token) + if cask.installed? + token = pretty_installed token + end + token +end + module Hbc module Utils def self.gain_permissions_remove(path, command: SystemCommand) -- cgit v1.2.3 From f93fd970d59c097a7bc55ba88ccdb90cd68a845b Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Sat, 11 Mar 2017 15:20:24 -0800 Subject: Speed up checking if cask is installed in search Switched from loading a cask and checking the installed? variable to checking for it in the caskroom directory like search does outside cask --- Library/Homebrew/cask/lib/hbc/utils.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index ef00104f9..fd786e318 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -37,8 +37,7 @@ def odebug(title, *sput) end def highlight_installed(token) - cask = Hbc.load(token) - if cask.installed? + if (Hbc.caskroom/token).directory? token = pretty_installed token end token -- cgit v1.2.3 From 4472daec2f0e98214cb0337ec9411ed62d700082 Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Sat, 11 Mar 2017 16:21:18 -0800 Subject: Updated highlight_installed to use Cask.installed? --- Library/Homebrew/cask/lib/hbc/utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index fd786e318..32db3c261 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -37,7 +37,7 @@ def odebug(title, *sput) end def highlight_installed(token) - if (Hbc.caskroom/token).directory? + if Hbc::Cask.new(token).installed? token = pretty_installed token end token -- cgit v1.2.3 From 6162a5e41f0a0e6d74d5a627ab8d9e7f1ddd3966 Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Sat, 11 Mar 2017 16:25:02 -0800 Subject: Moved highlight_installed from utils.rb to search.rb --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 7 +++++++ Library/Homebrew/cask/lib/hbc/utils.rb | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index a054358db..cc8657632 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -53,6 +53,13 @@ module Hbc puts Formatter.columns(highlighted) end + def self.highlight_installed(token) + if Hbc::Cask.new(token).installed? + token = pretty_installed token + end + token + end + def self.help "searches all known Casks" end diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index 32db3c261..ef3e5eda3 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -36,13 +36,6 @@ def odebug(title, *sput) puts sput unless sput.empty? end -def highlight_installed(token) - if Hbc::Cask.new(token).installed? - token = pretty_installed token - end - token -end - module Hbc module Utils def self.gain_permissions_remove(path, command: SystemCommand) -- cgit v1.2.3 From 250f3445b70ee09cdce4685d500b591978dbf63d Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Sat, 11 Mar 2017 16:28:41 -0800 Subject: Removed Hbc:: --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index cc8657632..68d725755 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -54,7 +54,7 @@ module Hbc end def self.highlight_installed(token) - if Hbc::Cask.new(token).installed? + if Cask.new(token).installed? token = pretty_installed token end token -- cgit v1.2.3 From 2080c360e26868efc08a0603c507a0be44c37b67 Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Mon, 13 Mar 2017 17:52:32 -0500 Subject: Added tests for highlight installed and fixed style errors --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 9 +++------ Library/Homebrew/test/cask/cli/search_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 68d725755..992aca583 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -49,15 +49,12 @@ module Hbc else ohai "Partial matches" end - highlighted = partial_matches.map { |match| highlight_installed match } - puts Formatter.columns(highlighted) + puts Formatter.columns(partial_matches.map(&method(:highlight_installed))) end def self.highlight_installed(token) - if Cask.new(token).installed? - token = pretty_installed token - end - token + return token unless Cask.new(token).installed? + pretty_installed token end def self.help diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 0bcff809a..cc4e0ae63 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -56,4 +56,16 @@ describe Hbc::CLI::Search, :cask do Hbc::CLI::Search.run("caskroom") }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout end + + it "doesn't highlight not installed packages" do + expect(Hbc::CLI::Search.highlight_installed "local-caffeine").to eq("local-caffeine") + end + + it "highlights installed packages" do + shutup do + Hbc::CLI::Install.run("local-caffeine") + end + + expect(Hbc::CLI::Search.highlight_installed "local-caffeine").to eq(pretty_installed "local-caffeine") + end end -- cgit v1.2.3 From b42ccece49d88874b8221570f62c08366b9d5eab Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Mon, 13 Mar 2017 19:15:41 -0500 Subject: Style changes --- Library/Homebrew/test/cask/cli/search_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index cc4e0ae63..cbd8ceb9d 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -58,14 +58,14 @@ describe Hbc::CLI::Search, :cask do end it "doesn't highlight not installed packages" do - expect(Hbc::CLI::Search.highlight_installed "local-caffeine").to eq("local-caffeine") + expect(Hbc::CLI::Search.highlight_installed("local-caffeine")).to eq("local-caffeine") end it "highlights installed packages" do shutup do - Hbc::CLI::Install.run("local-caffeine") + Hbc::CLI::Install.run("local-caffeine") end - expect(Hbc::CLI::Search.highlight_installed "local-caffeine").to eq(pretty_installed "local-caffeine") + expect(Hbc::CLI::Search.highlight_installed("local-caffeine")).to eq(pretty_installed("local-caffeine")) end end -- cgit v1.2.3 From 48e4463f5b458c731c6bbbaa200dd805bad32de0 Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Mon, 13 Mar 2017 19:43:08 -0500 Subject: Fixed test case wording --- Library/Homebrew/test/cask/cli/search_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index cbd8ceb9d..9843a6de6 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -57,7 +57,7 @@ describe Hbc::CLI::Search, :cask do }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout end - it "doesn't highlight not installed packages" do + it "doesn't highlight packages that aren't installed" do expect(Hbc::CLI::Search.highlight_installed("local-caffeine")).to eq("local-caffeine") end -- cgit v1.2.3