cmd/search: notification on attempted regex searches

Closes Homebrew/homebrew#38760.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Alex Dunn 2015-04-17 12:07:45 -07:00 committed by Mike McQuaid
parent 3287c5f388
commit d85f2dabca

View File

@ -61,7 +61,16 @@ module Homebrew
end
end
end
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .]
bad_regex = metacharacters.any? do |char|
ARGV.any? do |arg|
arg.include?(char) && !arg.start_with?('/')
end
end
if ARGV.any? && bad_regex
ohai "Did you mean to perform a regular expression search?"
ohai "Surround your query with /slashes/ to search by regex."
end
raise SEARCH_ERROR_QUEUE.pop unless SEARCH_ERROR_QUEUE.empty?
end