mirror of
https://github.com/wavetermdev/homebrew-cask.git
synced 2026-08-05 13:43:24 -07:00
Improve cash search
Ignore all the hyphens in cask title and search term make "brew cask search" ignore case like #2461 restore search by regular expression feature
This commit is contained in:
+10
-2
@@ -2,9 +2,17 @@ class Cask::CLI::Search
|
||||
def self.run(*arguments)
|
||||
search_term, *rest = *arguments
|
||||
casks = {}
|
||||
casks = Cask::CLI.nice_listing(Cask.all_titles.grep(/#{search_term}/i))
|
||||
if search_term =~ %r{^/(.*)/$}
|
||||
search_regexp = $1
|
||||
casks = Cask.all_titles.grep(/#{search_regexp}/i)
|
||||
else
|
||||
all_titles = Cask.all_titles
|
||||
no_hyphens_titles = all_titles.map {|t|t.gsub('-', '')}
|
||||
no_hyphens_search_term = search_term.gsub('-', '')
|
||||
casks = no_hyphens_titles.grep(/#{no_hyphens_search_term}/i) {|t| all_titles[no_hyphens_titles.index(t)]}
|
||||
end
|
||||
unless casks.empty?
|
||||
puts_columns casks
|
||||
puts_columns Cask::CLI.nice_listing casks
|
||||
else
|
||||
puts "No cask found for \"#{search_term}\"."
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user