From 00803b1a0b2a302a84871a05ae2abbdfe7f01a5c Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 23 Aug 2017 03:23:33 +0200 Subject: [PATCH 01/13] brew cask search without query just outputs all available cask tokens --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index e89dced925..42be4592ae 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -2,8 +2,12 @@ module Hbc class CLI class Search < AbstractCommand def run - results = self.class.search(*args) - self.class.render_results(*results) + if args.empty? + puts Formatter.columns(CLI.nice_listing(Hbc.all_tokens)) + else + results = self.class.search(*args) + self.class.render_results(*results) + end end def self.extract_regexp(string) From a5640fdfeeea7347e51c14abac481f4b210527ab Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 23 Aug 2017 16:54:21 +0200 Subject: [PATCH 02/13] Added rescue block for the remote cask search failure --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 42be4592ae..9f4f9f31d1 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -19,8 +19,18 @@ module Hbc end def self.search_remote(query) - matches = GitHub.search_code(user: "caskroom", path: "Casks", - filename: query, extension: "rb") + matches = begin GitHub.search_code( + user: "caskroom", + path: "Casks", + filename: query, + extension: "rb" + ) + rescue Exception => e + onoe e + $stderr.puts e.backtrace + [] + end + matches.map do |match| tap = Tap.fetch(match["repository"]["full_name"]) next if tap.installed? From 9e2caa8d6a55c0c48c46d916520ab827a23f504e Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 23 Aug 2017 17:54:01 +0200 Subject: [PATCH 03/13] Fixed style issues --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 9f4f9f31d1..fbc2487ae2 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -23,14 +23,13 @@ module Hbc user: "caskroom", path: "Casks", filename: query, - extension: "rb" + extension: "rb", ) - rescue Exception => e + rescue StandardError => e onoe e $stderr.puts e.backtrace [] end - matches.map do |match| tap = Tap.fetch(match["repository"]["full_name"]) next if tap.installed? From 15d2a9c7cd2ab37ec7b790ad1c0a4aa653826a60 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 23 Aug 2017 19:47:47 +0200 Subject: [PATCH 04/13] Formatting fix --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index fbc2487ae2..2b290bbdf2 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -19,12 +19,13 @@ module Hbc end def self.search_remote(query) - matches = begin GitHub.search_code( - user: "caskroom", - path: "Casks", - filename: query, - extension: "rb", - ) + matches = begin + GitHub.search_code( + user: "caskroom", + path: "Casks", + filename: query, + extension: "rb", + ) rescue StandardError => e onoe e $stderr.puts e.backtrace From 2cc6ef48ff6927db568616d2099b9d8163b90652 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 24 Aug 2017 00:29:22 +0200 Subject: [PATCH 05/13] Narrowed rescued error type --- 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 2b290bbdf2..785f4b4b11 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -26,7 +26,7 @@ module Hbc filename: query, extension: "rb", ) - rescue StandardError => e + rescue GitHub::Error => e onoe e $stderr.puts e.backtrace [] From 3b7e0d8dbe3d9652b6d9a81f01bc3e68479b17bc Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 01:54:24 +0200 Subject: [PATCH 06/13] Added tests for cask search with online search failure --- Library/Homebrew/test/cask/cli/search_spec.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index e237ad464f..e7065404d7 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -22,16 +22,29 @@ describe Hbc::CLI::Search, :cask do EOS end + it "returns matches even when online search failed" do + allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) + expect { + Hbc::CLI::Search.run("local") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + EOS + .and output(/^Error: reason\n/).to_stderr + end + it "shows that there are no Casks matching a search term that did not result in anything" do expect { Hbc::CLI::Search.run("foo-bar-baz") }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty end - it "lists all available Casks with no search term" do + it "lists all Casks available offline with no search term" do + allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) expect { Hbc::CLI::Search.run }.to output(/local-caffeine/).to_stdout.as_tty + .and not_to_output.to_stderr end it "ignores hyphens in search terms" do From 68c837f0412f0958817ee2d827b770f26d51bad6 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:01:08 +0200 Subject: [PATCH 07/13] Unified tests formatting for multiline output matching --- Library/Homebrew/test/cask/cli/search_spec.rb | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index e7065404d7..f3b693d991 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -36,7 +36,9 @@ describe Hbc::CLI::Search, :cask do it "shows that there are no Casks matching a search term that did not result in anything" do expect { Hbc::CLI::Search.run("foo-bar-baz") - }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + No Cask found for "foo-bar-baz". + EOS end it "lists all Casks available offline with no search term" do @@ -68,19 +70,29 @@ describe Hbc::CLI::Search, :cask do it "accepts a regexp argument" do expect { Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/") - }.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + ==> Regexp Matches + local-caffeine + EOS end - it "Returns both exact and partial matches" do + it "returns both exact and partial matches" do expect { Hbc::CLI::Search.run("test-opera") - }.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + ==> Exact Match + test-opera + ==> Partial Matches + test-opera-mail + EOS end it "does not search the Tap name" do expect { Hbc::CLI::Search.run("caskroom") - }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + No Cask found for "caskroom". + EOS end it "doesn't highlight packages that aren't installed" do From 29b0c7d7472dc26c8c8913db9a16e996ce68f6d2 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:05:35 +0200 Subject: [PATCH 08/13] Added a test for no-macthes output to non-TTY --- Library/Homebrew/test/cask/cli/search_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index f3b693d991..48a4d556d7 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -41,6 +41,13 @@ describe Hbc::CLI::Search, :cask do EOS end + it "doesn't output anything to non-TTY stdout when there are no matches" do + expect { + Hbc::CLI::Search.run("foo-bar-baz") + }.to not_to_output.to_stdout + .and not_to_output.to_stderr + end + it "lists all Casks available offline with no search term" do allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) expect { From 2a3f83b8d4ceeca370a60bbcb494990a2bd20801 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:37:39 +0200 Subject: [PATCH 09/13] Changed online search failure to warning and removed stacktrace --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 785f4b4b11..8fb8b91ecc 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -26,9 +26,8 @@ module Hbc filename: query, extension: "rb", ) - rescue GitHub::Error => e - onoe e - $stderr.puts e.backtrace + rescue GitHub::Error => error + opoo "Online search failed: #{error}\n" [] end matches.map do |match| From 6ac0b9881de5a00a884ca5e59553583d1ada0fc5 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:43:28 +0200 Subject: [PATCH 10/13] Fixed test for the changed error message --- 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 48a4d556d7..06f0b4b32c 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -30,7 +30,7 @@ describe Hbc::CLI::Search, :cask do local-caffeine local-transmission EOS - .and output(/^Error: reason\n/).to_stderr + .and output(/^Warning: Online search failed: reason/).to_stderr end it "shows that there are no Casks matching a search term that did not result in anything" do From 68dd0ac918639e6c1cbe7ba1800cda3646ba4e0b Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 31 Aug 2017 03:03:00 +0200 Subject: [PATCH 11/13] Changed warning message as recommended by @reitermarkus --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 2 +- Library/Homebrew/test/cask/cli/search_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 8fb8b91ecc..d56d0c81fe 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -27,7 +27,7 @@ module Hbc extension: "rb", ) rescue GitHub::Error => error - opoo "Online search failed: #{error}\n" + opoo "Error searching on GitHub: #{error}\n" [] end matches.map do |match| diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 06f0b4b32c..85bb42c56f 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -30,7 +30,7 @@ describe Hbc::CLI::Search, :cask do local-caffeine local-transmission EOS - .and output(/^Warning: Online search failed: reason/).to_stderr + .and output(/^Warning: Error searching on GitHub: reason/).to_stderr end it "shows that there are no Casks matching a search term that did not result in anything" do From 8e5ad9ad9be3587001fb92b4367ddb7cc4c7fc8c Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 2 Sep 2017 02:29:56 +0200 Subject: [PATCH 12/13] Minor tests formatting change --- Library/Homebrew/test/cask/cli/search_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 85bb42c56f..6dc9805903 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -42,18 +42,16 @@ describe Hbc::CLI::Search, :cask do end it "doesn't output anything to non-TTY stdout when there are no matches" do - expect { - Hbc::CLI::Search.run("foo-bar-baz") - }.to not_to_output.to_stdout - .and not_to_output.to_stderr + expect { Hbc::CLI::Search.run("foo-bar-baz") } + .to not_to_output.to_stdout + .and not_to_output.to_stderr end it "lists all Casks available offline with no search term" do allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) - expect { - Hbc::CLI::Search.run - }.to output(/local-caffeine/).to_stdout.as_tty - .and not_to_output.to_stderr + expect { Hbc::CLI::Search.run } + .to output(/local-caffeine/).to_stdout.as_tty + .and not_to_output.to_stderr end it "ignores hyphens in search terms" do From 50db7db72449d48590352149d778653086b73dbb Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 2 Sep 2017 14:27:02 +0200 Subject: [PATCH 13/13] Updated cask search manpage --- Library/Homebrew/manpages/brew-cask.1.md | 13 +++++++------ manpages/brew-cask.1 | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/manpages/brew-cask.1.md b/Library/Homebrew/manpages/brew-cask.1.md index bfb9cd7a53..715d8fd770 100644 --- a/Library/Homebrew/manpages/brew-cask.1.md +++ b/Library/Homebrew/manpages/brew-cask.1.md @@ -1,5 +1,5 @@ brew-cask(1) - a friendly binary installer for macOS -======================================================== +==================================================== ## SYNOPSIS @@ -85,7 +85,7 @@ names, and other aspects of this manual are still subject to change. If is given, summarize the staged files associated with the given Cask. - + * `outdated` [--greedy] [--verbose|--quiet] [ ...]: Without token arguments, display all the installed Casks that have newer versions available in the tap; otherwise check only the tokens given @@ -101,9 +101,10 @@ names, and other aspects of this manual are still subject to change. Reinstall the given Cask. * `search` or `-S` [ | //]: - Without an argument, display all Casks available for install; otherwise - perform a substring search of known Cask tokens for or, if the - text is delimited by slashes (//), it is interpreted as a + Without an argument, display all locally available Casks for install; no + online search is performed. + Otherwise perform a substring search of known Cask tokens for or, + if the text is delimited by slashes (//), it is interpreted as a Ruby regular expression. * `style` [--fix] [ ... ]: @@ -255,7 +256,7 @@ Environment variables specific to Homebrew-Cask: export HOMEBREW_CASK_OPTS='--appdir=~/Applications --fontdir=/Library/Fonts' Other environment variables: - + * `SUDO_ASKPASS`: When this variable is set, Homebrew-Cask will call `sudo`(8) with the `-A` option. diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index 763d78ebe6..f8f58a123b 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -103,7 +103,7 @@ Reinstall the given Cask\. . .TP \fBsearch\fR or \fB\-S\fR [\fItext\fR | /\fIregexp\fR/] -Without an argument, display all Casks available for install; otherwise perform a substring search of known Cask tokens for \fItext\fR or, if the text is delimited by slashes (/\fIregexp\fR/), it is interpreted as a Ruby regular expression\. +Without an argument, display all locally available Casks for install; no online search is performed\. Otherwise perform a substring search of known Cask tokens for \fItext\fR or, if the text is delimited by slashes (/\fIregexp\fR/), it is interpreted as a Ruby regular expression\. . .TP \fBstyle\fR [\-\-fix] [ \fItoken\fR \.\.\. ]