Merge brew cask search
into brew search
.
This commit is contained in:
parent
f7d0c89c21
commit
da193d2f7e
@ -15,13 +15,11 @@ require "hbc/download"
|
||||
require "hbc/download_strategy"
|
||||
require "hbc/exceptions"
|
||||
require "hbc/installer"
|
||||
require "hbc/config"
|
||||
require "hbc/macos"
|
||||
require "hbc/pkg"
|
||||
require "hbc/staged"
|
||||
require "hbc/system_command"
|
||||
require "hbc/topological_hash"
|
||||
require "hbc/url"
|
||||
require "hbc/utils"
|
||||
require "hbc/verify"
|
||||
require "hbc/version"
|
||||
|
@ -1,4 +1,5 @@
|
||||
require "hbc/cask_loader"
|
||||
require "hbc/config"
|
||||
require "hbc/dsl"
|
||||
require "hbc/metadata"
|
||||
require "searchable"
|
||||
|
@ -2,6 +2,9 @@ require "optparse"
|
||||
require "shellwords"
|
||||
|
||||
require "extend/optparse"
|
||||
|
||||
require "hbc/config"
|
||||
|
||||
require "hbc/cli/options"
|
||||
|
||||
require "hbc/cli/abstract_command"
|
||||
|
@ -1,3 +1,5 @@
|
||||
require "hbc/utils"
|
||||
|
||||
require "hbc/container/base"
|
||||
require "hbc/container/air"
|
||||
require "hbc/container/bzip2"
|
||||
|
@ -2,6 +2,9 @@ require "locale"
|
||||
|
||||
require "hbc/artifact"
|
||||
|
||||
require "hbc/caskroom"
|
||||
require "hbc/exceptions"
|
||||
|
||||
require "hbc/dsl/appcast"
|
||||
require "hbc/dsl/base"
|
||||
require "hbc/dsl/caveats"
|
||||
@ -16,6 +19,8 @@ require "hbc/dsl/uninstall_postflight"
|
||||
require "hbc/dsl/uninstall_preflight"
|
||||
require "hbc/dsl/version"
|
||||
|
||||
require "hbc/url"
|
||||
|
||||
module Hbc
|
||||
class DSL
|
||||
ORDINARY_ARTIFACT_CLASSES = [
|
||||
|
@ -18,6 +18,7 @@ require "missing_formula"
|
||||
require "descriptions"
|
||||
require "cli_parser"
|
||||
require "search"
|
||||
require "hbc/cask_loader"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
@ -58,32 +59,57 @@ module Homebrew
|
||||
query = args.remaining.join(" ")
|
||||
string_or_regex = query_regexp(query)
|
||||
Descriptions.search(string_or_regex, :desc).print
|
||||
elsif args.remaining.first =~ HOMEBREW_TAP_FORMULA_REGEX
|
||||
query = args.remaining.first
|
||||
|
||||
results = begin
|
||||
[Formulary.factory(query).name]
|
||||
rescue FormulaUnavailableError
|
||||
_, _, name = query.split("/", 3)
|
||||
remote_results = search_taps(name)
|
||||
[*remote_results[:formulae], *remote_results[:casks]].sort
|
||||
end
|
||||
|
||||
puts Formatter.columns(results) unless results.empty?
|
||||
else
|
||||
query = args.remaining.join(" ")
|
||||
string_or_regex = query_regexp(query)
|
||||
local_results = search_formulae(string_or_regex)
|
||||
puts Formatter.columns(local_results.sort) unless local_results.empty?
|
||||
|
||||
remote_results = search_taps(query)
|
||||
tap_results = [*remote_results[:formulae], *remote_results[:casks]].sort
|
||||
puts Formatter.columns(tap_results) unless tap_results.empty?
|
||||
remote_results = if query.match?(HOMEBREW_TAP_FORMULA_REGEX) || query.match?(HOMEBREW_TAP_CASK_REGEX)
|
||||
_, _, name = query.split("/", 3)
|
||||
search_taps(name, silent: true)
|
||||
else
|
||||
search_taps(query, silent: true)
|
||||
end
|
||||
|
||||
local_formulae = if query.match?(HOMEBREW_TAP_FORMULA_REGEX)
|
||||
begin
|
||||
[Formulary.factory(query).name]
|
||||
rescue FormulaUnavailableError
|
||||
[]
|
||||
end
|
||||
else
|
||||
search_formulae(string_or_regex)
|
||||
end
|
||||
|
||||
remote_formulae = remote_results[:formulae]
|
||||
all_formulae = local_formulae + remote_formulae
|
||||
|
||||
local_casks = if query.match?(HOMEBREW_TAP_CASK_REGEX)
|
||||
begin
|
||||
[Hbc::CaskLoader.load(query).token]
|
||||
rescue Hbc::CaskUnavailableError
|
||||
[]
|
||||
end
|
||||
else
|
||||
search_casks(string_or_regex)
|
||||
end
|
||||
|
||||
remote_casks = remote_results[:casks]
|
||||
all_casks = local_casks + remote_casks
|
||||
|
||||
if all_formulae.any?
|
||||
ohai "Formulae"
|
||||
puts Formatter.columns(all_formulae)
|
||||
end
|
||||
|
||||
if all_casks.any?
|
||||
puts if all_formulae.any?
|
||||
ohai "Casks"
|
||||
puts Formatter.columns(all_casks)
|
||||
end
|
||||
|
||||
if $stdout.tty?
|
||||
count = local_results.length + tap_results.length
|
||||
count = all_formulae.count + all_casks.count
|
||||
|
||||
ohai "Searching blacklisted, migrated and deleted formulae..."
|
||||
if reason = MissingFormula.reason(query, silent: true)
|
||||
if count.positive?
|
||||
puts
|
||||
@ -91,7 +117,7 @@ module Homebrew
|
||||
end
|
||||
puts reason
|
||||
elsif count.zero?
|
||||
puts "No formula found for #{query.inspect}."
|
||||
puts "No formula or cask found for #{query.inspect}."
|
||||
GitHub.print_pull_requests_matching(query)
|
||||
end
|
||||
end
|
||||
|
@ -40,7 +40,7 @@ module Homebrew
|
||||
tap = Tap.fetch(match["repository"]["full_name"])
|
||||
full_name = "#{tap.name}/#{name}"
|
||||
|
||||
next if tap.installed? && !match["path"].start_with?("Casks/")
|
||||
next if tap.installed?
|
||||
|
||||
if match["path"].start_with?("Casks/")
|
||||
results[:casks] = [*results[:casks], full_name].sort
|
||||
@ -53,9 +53,6 @@ module Homebrew
|
||||
end
|
||||
|
||||
def search_formulae(string_or_regex)
|
||||
# Use stderr to avoid breaking parsed output
|
||||
$stderr.puts Formatter.headline("Searching local taps...", color: :blue)
|
||||
|
||||
aliases = Formula.alias_full_names
|
||||
results = (Formula.full_names + aliases)
|
||||
.extend(Searchable)
|
||||
|
@ -15,7 +15,6 @@ describe "brew search", :integration_test do
|
||||
it "supports searching by name" do
|
||||
expect { brew "search", "testball" }
|
||||
.to output(/testball/).to_stdout
|
||||
.and output(/Searching/).to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
||||
@ -26,12 +25,11 @@ describe "brew search", :integration_test do
|
||||
.and be_a_success
|
||||
end
|
||||
|
||||
it "falls back to a GitHub tap search when no formula is found", :needs_network, retry: 3 do
|
||||
it "falls back to a GitHub tap search when no formula is found", :needs_macos, :needs_network, retry: 3 do
|
||||
setup_remote_tap "homebrew/cask"
|
||||
|
||||
expect { brew "search", "homebrew/cask/firefox" }
|
||||
.to output(/firefox/).to_stdout
|
||||
.and output(/Searching/).to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user