Commit 67833906 authored by Ed Reel's avatar Ed Reel

Fix 'crew whatprovides' based on @jam's suggestion

  - Filters based on a regex pattern instead of the full path to the file
parent d84f285c
...@@ -65,24 +65,51 @@ def search (pkgName, silent = false) ...@@ -65,24 +65,51 @@ def search (pkgName, silent = false)
abort "package #{pkgName} not found :(" abort "package #{pkgName} not found :("
end end
def whatprovides (pkgName, silent = false) def whatprovides (pkgName)
found = nil fileArray = []
packageName = '' arg = ARGV[1].dup
fileName = pkgName + "\n" op = '*'
Find.find (CREW_LIB_PATH + 'packages') do |filename| search = arg
packageName = File.basename filename, '.rb' if arg[0] == '^'
fileList = CREW_CONFIG_PATH + 'meta/' + packageName + '.filelist' op = '^'
if File.file?(fileList) search = arg[1..arg.length - 1]
File.readlines(fileList).each do |line| end
if line == fileName if arg[-1] == '$'
found = true op = '$'
break search = arg[0..arg.length - 2]
end
Find.find (CREW_CONFIG_PATH + 'meta/') do |packageList|
if File.file? packageList
if packageList[/\.filelist$/]
packageName = File.basename packageList, '.filelist'
File.readlines(packageList).each do |line|
found = nil
case op
when '*'
found = line[/#{Regexp.quote(search)}/]
when '^'
found = line[/^#{Regexp.quote(search)}/]
when '$'
found = line[/#{Regexp.quote(search)}$/]
end
if found
fileLine = packageName + ': ' + line
if not fileArray.include? fileLine
fileArray.push(fileLine)
end
end
end end
end end
end end
break if found
end end
puts packageName + ': ' + fileName if found if not fileArray.empty?
fileCount = 0
fileArray.sort.each do |item|
puts item
fileCount += 1
end
puts "\nTotal found: #{fileCount}"
end
end end
def update def update
...@@ -394,7 +421,7 @@ when "whatprovides" ...@@ -394,7 +421,7 @@ when "whatprovides"
if @pkgName if @pkgName
whatprovides @pkgName whatprovides @pkgName
else else
puts "Usage: crew whatprovides [filepath]" puts "Usage: crew whatprovides [pattern]"
end end
when "download" when "download"
search @pkgName search @pkgName
......
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