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,6 +77,40 @@ 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?
|
||||||
|
search_pull_requests(query, args)
|
||||||
|
else
|
||||||
|
search_names(query, string_or_regex, args)
|
||||||
|
end
|
||||||
|
|
||||||
|
print_regex_help(args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_regex_help(args)
|
||||||
|
return unless $stdout.tty?
|
||||||
|
|
||||||
|
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ?].freeze
|
||||||
|
return unless metacharacters.any? do |char|
|
||||||
|
args.named.any? do |arg|
|
||||||
|
arg.include?(char) && !arg.start_with?("/")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
opoo <<~EOS
|
||||||
|
Did you mean to perform a regular expression search?
|
||||||
|
Surround your query with /slashes/ to search locally by regex.
|
||||||
|
EOS
|
||||||
|
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?
|
only = if args.open? && !args.closed?
|
||||||
"open"
|
"open"
|
||||||
elsif args.closed? && !args.open?
|
elsif args.closed? && !args.open?
|
||||||
@ -88,7 +118,9 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
GitHub.print_pull_requests_matching(query, only)
|
GitHub.print_pull_requests_matching(query, only)
|
||||||
else
|
end
|
||||||
|
|
||||||
|
def search_names(query, string_or_regex, args)
|
||||||
remote_results = search_taps(query, silent: true)
|
remote_results = search_taps(query, silent: true)
|
||||||
|
|
||||||
local_formulae = search_formulae(string_or_regex)
|
local_formulae = search_formulae(string_or_regex)
|
||||||
@ -121,19 +153,4 @@ module Homebrew
|
|||||||
|
|
||||||
odie "No formulae or casks found for #{query.inspect}." if count.zero?
|
odie "No formulae or casks found for #{query.inspect}." if count.zero?
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless $stdout.tty?
|
|
||||||
|
|
||||||
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ?].freeze
|
|
||||||
return unless metacharacters.any? do |char|
|
|
||||||
args.named.any? do |arg|
|
|
||||||
arg.include?(char) && !arg.start_with?("/")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
opoo <<~EOS
|
|
||||||
Did you mean to perform a regular expression search?
|
|
||||||
Surround your query with /slashes/ to search locally by regex.
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user