Add remote search to brew cask search.
This commit is contained in:
parent
2bda194bd9
commit
238cd5430f
@ -13,6 +13,15 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.search_remote(query)
|
||||||
|
matches = GitHub.search_code("user:caskroom", "path:Casks", "filename:#{query}", "extension:rb")
|
||||||
|
[*matches].map do |match|
|
||||||
|
tap = Tap.fetch(match["repository"]["full_name"])
|
||||||
|
next if tap.installed?
|
||||||
|
"#{tap.name}/#{File.basename(match["path"], ".rb")}"
|
||||||
|
end.compact
|
||||||
|
end
|
||||||
|
|
||||||
def self.search(*arguments)
|
def self.search(*arguments)
|
||||||
exact_match = nil
|
exact_match = nil
|
||||||
partial_matches = []
|
partial_matches = []
|
||||||
@ -29,27 +38,34 @@ module Hbc
|
|||||||
partial_matches = simplified_tokens.grep(/#{simplified_search_term}/i) { |t| all_tokens[simplified_tokens.index(t)] }
|
partial_matches = simplified_tokens.grep(/#{simplified_search_term}/i) { |t| all_tokens[simplified_tokens.index(t)] }
|
||||||
partial_matches.delete(exact_match)
|
partial_matches.delete(exact_match)
|
||||||
end
|
end
|
||||||
[exact_match, partial_matches, search_term]
|
|
||||||
|
remote_matches = search_remote(search_term)
|
||||||
|
|
||||||
|
[exact_match, partial_matches, remote_matches, search_term]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render_results(exact_match, partial_matches, search_term)
|
def self.render_results(exact_match, partial_matches, remote_matches, search_term)
|
||||||
if !exact_match && partial_matches.empty?
|
if !exact_match && partial_matches.empty?
|
||||||
puts "No Cask found for \"#{search_term}\"."
|
puts "No Cask found for \"#{search_term}\"."
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if exact_match
|
if exact_match
|
||||||
ohai "Exact match"
|
ohai "Exact Match"
|
||||||
puts highlight_installed exact_match
|
puts highlight_installed exact_match
|
||||||
end
|
end
|
||||||
|
|
||||||
return if partial_matches.empty?
|
unless partial_matches.empty?
|
||||||
|
if extract_regexp search_term
|
||||||
if extract_regexp search_term
|
ohai "Regexp Matches"
|
||||||
ohai "Regexp matches"
|
else
|
||||||
else
|
ohai "Partial Matches"
|
||||||
ohai "Partial matches"
|
end
|
||||||
|
puts Formatter.columns(partial_matches.map(&method(:highlight_installed)))
|
||||||
end
|
end
|
||||||
puts Formatter.columns(partial_matches.map(&method(:highlight_installed)))
|
|
||||||
|
return if remote_matches.empty?
|
||||||
|
ohai "Remote Matches"
|
||||||
|
puts Formatter.columns(remote_matches.map(&method(:highlight_installed)))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.highlight_installed(token)
|
def self.highlight_installed(token)
|
||||||
|
|||||||
@ -3,7 +3,7 @@ describe Hbc::CLI::Search, :cask do
|
|||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Search.run("local")
|
Hbc::CLI::Search.run("local")
|
||||||
}.to output(<<-EOS.undent).to_stdout
|
}.to output(<<-EOS.undent).to_stdout
|
||||||
==> Partial matches
|
==> Partial Matches
|
||||||
local-caffeine
|
local-caffeine
|
||||||
local-transmission
|
local-transmission
|
||||||
EOS
|
EOS
|
||||||
@ -42,13 +42,13 @@ describe Hbc::CLI::Search, :cask do
|
|||||||
it "accepts a regexp argument" do
|
it "accepts a regexp argument" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/")
|
Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/")
|
||||||
}.to output("==> Regexp matches\nlocal-caffeine\n").to_stdout
|
}.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
it "Returns both exact and partial matches" do
|
it "Returns both exact and partial matches" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Search.run("test-opera")
|
Hbc::CLI::Search.run("test-opera")
|
||||||
}.to output(/^==> Exact match\ntest-opera\n==> Partial matches\ntest-opera-mail/).to_stdout
|
}.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not search the Tap name" do
|
it "does not search the Tap name" do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user