Merge pull request #3084 from laughedelic/cask/search-offline
Offline cask search and listing all available casks
This commit is contained in:
commit
2f133725a2
@ -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)
|
||||
@ -15,8 +19,17 @@ 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 GitHub::Error => error
|
||||
opoo "Error searching on GitHub: #{error}\n"
|
||||
[]
|
||||
end
|
||||
matches.map do |match|
|
||||
tap = Tap.fetch(match["repository"]["full_name"])
|
||||
next if tap.installed?
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
brew-cask(1) - a friendly binary installer for macOS
|
||||
========================================================
|
||||
====================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
@ -101,9 +101,10 @@ names, and other aspects of this manual are still subject to change.
|
||||
Reinstall the given Cask.
|
||||
|
||||
* `search` or `-S` [<text> | /<regexp>/]:
|
||||
Without an argument, display all Casks available for install; otherwise
|
||||
perform a substring search of known Cask tokens for <text> or, if the
|
||||
text is delimited by slashes (/<regexp>/), 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 <text> or,
|
||||
if the text is delimited by slashes (/<regexp>/), it is interpreted as a
|
||||
Ruby regular expression.
|
||||
|
||||
* `style` [--fix] [ <token> ... ]:
|
||||
|
||||
@ -22,16 +22,36 @@ 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(/^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
|
||||
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 available Casks with no search term" do
|
||||
expect {
|
||||
Hbc::CLI::Search.run
|
||||
}.to output(/local-caffeine/).to_stdout.as_tty
|
||||
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 { 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
|
||||
@ -55,19 +75,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
|
||||
|
||||
@ -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 \.\.\. ]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user