search: split up command into multiple methods
This commit is contained in:
parent
e38e25dfd1
commit
896aff0cf2
@ -69,11 +69,7 @@ module Homebrew
|
|||||||
def search
|
def search
|
||||||
args = search_args.parse
|
args = search_args.parse
|
||||||
|
|
||||||
if (package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] })
|
return if search_package_manager(args)
|
||||||
_, url = package_manager
|
|
||||||
exec_browser url.call(URI.encode_www_form_component(args.named.join(" ")))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
query = args.named.join(" ")
|
query = args.named.join(" ")
|
||||||
string_or_regex = query_regexp(query)
|
string_or_regex = query_regexp(query)
|
||||||
@ -81,47 +77,15 @@ module Homebrew
|
|||||||
if args.desc?
|
if args.desc?
|
||||||
search_descriptions(string_or_regex, args)
|
search_descriptions(string_or_regex, args)
|
||||||
elsif args.pull_request?
|
elsif args.pull_request?
|
||||||
only = if args.open? && !args.closed?
|
search_pull_requests(query, args)
|
||||||
"open"
|
|
||||||
elsif args.closed? && !args.open?
|
|
||||||
"closed"
|
|
||||||
end
|
|
||||||
|
|
||||||
GitHub.print_pull_requests_matching(query, only)
|
|
||||||
else
|
else
|
||||||
remote_results = search_taps(query, silent: true)
|
search_names(query, string_or_regex, args)
|
||||||
|
|
||||||
local_formulae = search_formulae(string_or_regex)
|
|
||||||
remote_formulae = remote_results[:formulae]
|
|
||||||
all_formulae = local_formulae + remote_formulae
|
|
||||||
|
|
||||||
local_casks = search_casks(string_or_regex)
|
|
||||||
remote_casks = remote_results[:casks]
|
|
||||||
all_casks = local_casks + remote_casks
|
|
||||||
print_formulae = args.formula?
|
|
||||||
print_casks = args.cask?
|
|
||||||
print_formulae = print_casks = true if !print_formulae && !print_casks
|
|
||||||
|
|
||||||
ohai "Formulae", Formatter.columns(all_formulae) if print_formulae && all_formulae.any?
|
|
||||||
|
|
||||||
if print_casks && all_casks.any?
|
|
||||||
puts if args.formula? && all_formulae.any?
|
|
||||||
ohai "Casks", Formatter.columns(all_casks)
|
|
||||||
end
|
|
||||||
|
|
||||||
count = all_formulae.count + all_casks.count
|
|
||||||
|
|
||||||
if $stdout.tty? && (reason = MissingFormula.reason(query, silent: true)) && local_casks.exclude?(query)
|
|
||||||
if count.positive?
|
|
||||||
puts
|
|
||||||
puts "If you meant #{query.inspect} specifically:"
|
|
||||||
end
|
|
||||||
puts reason
|
|
||||||
end
|
|
||||||
|
|
||||||
odie "No formulae or casks found for #{query.inspect}." if count.zero?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print_regex_help(args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_regex_help(args)
|
||||||
return unless $stdout.tty?
|
return unless $stdout.tty?
|
||||||
|
|
||||||
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ?].freeze
|
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ?].freeze
|
||||||
@ -136,4 +100,57 @@ module Homebrew
|
|||||||
Surround your query with /slashes/ to search locally by regex.
|
Surround your query with /slashes/ to search locally by regex.
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search_package_manager(args)
|
||||||
|
package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] }
|
||||||
|
return false if package_manager.nil?
|
||||||
|
|
||||||
|
_, url = package_manager
|
||||||
|
exec_browser url.call(URI.encode_www_form_component(args.named.join(" ")))
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def search_pull_requests(query, args)
|
||||||
|
only = if args.open? && !args.closed?
|
||||||
|
"open"
|
||||||
|
elsif args.closed? && !args.open?
|
||||||
|
"closed"
|
||||||
|
end
|
||||||
|
|
||||||
|
GitHub.print_pull_requests_matching(query, only)
|
||||||
|
end
|
||||||
|
|
||||||
|
def search_names(query, string_or_regex, args)
|
||||||
|
remote_results = search_taps(query, silent: true)
|
||||||
|
|
||||||
|
local_formulae = search_formulae(string_or_regex)
|
||||||
|
remote_formulae = remote_results[:formulae]
|
||||||
|
all_formulae = local_formulae + remote_formulae
|
||||||
|
|
||||||
|
local_casks = search_casks(string_or_regex)
|
||||||
|
remote_casks = remote_results[:casks]
|
||||||
|
all_casks = local_casks + remote_casks
|
||||||
|
print_formulae = args.formula?
|
||||||
|
print_casks = args.cask?
|
||||||
|
print_formulae = print_casks = true if !print_formulae && !print_casks
|
||||||
|
|
||||||
|
ohai "Formulae", Formatter.columns(all_formulae) if print_formulae && all_formulae.any?
|
||||||
|
|
||||||
|
if print_casks && all_casks.any?
|
||||||
|
puts if args.formula? && all_formulae.any?
|
||||||
|
ohai "Casks", Formatter.columns(all_casks)
|
||||||
|
end
|
||||||
|
|
||||||
|
count = all_formulae.count + all_casks.count
|
||||||
|
|
||||||
|
if $stdout.tty? && (reason = MissingFormula.reason(query, silent: true)) && local_casks.exclude?(query)
|
||||||
|
if count.positive?
|
||||||
|
puts
|
||||||
|
puts "If you meant #{query.inspect} specifically:"
|
||||||
|
end
|
||||||
|
puts reason
|
||||||
|
end
|
||||||
|
|
||||||
|
odie "No formulae or casks found for #{query.inspect}." if count.zero?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user