Commit 6918a2c4 authored by Casey Strouse's avatar Casey Strouse Committed by Kazushi (Jam) Marukawa

Refactor search logic to support regex

`crew search` use to only return a single result if your query string
matched a package name exactly.

`crew search` now supports regex.

chronos@localhost / $ crew search ^lib
Found libpcap, version 1.8.1
Found libjpeg, version 9.1
Found libunwind, version 1.1
Found libxslt, version 1.1.28
Found libffi, version 3.0.13-1
Found libssh2, version 1.4.3
Found libtool, version 2.4.6
Found libpipeline, version 1.4.1
Found libevent, version 2.0.22
Found libxml2, version 2.9.2
Found libgd, version 2.0.33
Found libtiff, version 4.0.7
Found libpng, version 1.6.26
Found libsigsegv, version 2.10
parent d4d5a7d7
......@@ -153,6 +153,14 @@ def search (pkgName, silent = false)
abort "Package #{pkgName} not found. :(".lightred
end
def regexp_search(pkg_name)
results = Dir["#{CREW_LIB_PATH}packages/*.rb"] \
.select { |f| File.basename(f, '.rb') =~ Regexp.new(pkg_name, true) } \
.collect { |f| File.basename(f, '.rb') } \
.each { |f| set_package(f) }
abort "Package not found :(" unless results.length > 0
end
def help (pkgName)
case pkgName
when "build"
......@@ -663,7 +671,7 @@ when "help"
end
when "search"
if @pkgName
print_package @pkgName, true
regexp_search @pkgName
else
list_packages
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment