Extract search_brews method

This commit is contained in:
Adam Vandenberg 2010-06-17 10:45:16 -07:00
parent 6aeb848bd8
commit d84b8cf288
2 changed files with 12 additions and 10 deletions

View File

@ -399,6 +399,17 @@ def outdated_brews
return results
end
def search_brews text
require "formula"
formulae = Formulary.names with_aliases=true
if text =~ /^\/(.*)\/$/
return formulae.grep(Regexp.new($1))
else
search_term = Regexp.escape(text || "")
return formulae.grep(/.*#{search_term}.*/)
end
end
########################################################## class PrettyListing
class PrettyListing
def initialize path

View File

@ -130,16 +130,7 @@ begin
when 'search', '-S'
check_for_blacklisted_formula(ARGV.named)
require "formula"
formulae = Formulary.names with_aliases=true
if ARGV.first =~ /^\/(.*)\/$/
puts_columns formulae.grep(Regexp.new($1))
else
search_term = Regexp.escape(ARGV.first || "")
puts_columns formulae.grep(/.*#{search_term}.*/)
end
puts_columns search_brews(ARGV.first)
when 'edit'
if ARGV.named.empty?