Commit 0fdee308 authored by satmandu's avatar satmandu Committed by GitHub

Use grep in crew whatprovides (#5797)

* Use grep in crew whatprovides

* Add check for working grep.

* uprev
parent 003b8772
...@@ -35,7 +35,7 @@ Usage: ...@@ -35,7 +35,7 @@ Usage:
crew search [options] [<name> ...] crew search [options] [<name> ...]
crew update [options] [<compatible>] crew update [options] [<compatible>]
crew upgrade [options] [-k|--keep] [-s|--build-from-source] [<name> ...] crew upgrade [options] [-k|--keep] [-s|--build-from-source] [<name> ...]
crew whatprovides [options] <name> ... crew whatprovides [options] <pattern> ...
-c --color Use colors even if standard out is not a tty. -c --color Use colors even if standard out is not a tty.
-d --no-color Disable colors even if standard out is a tty. -d --no-color Disable colors even if standard out is a tty.
...@@ -486,20 +486,13 @@ def files (pkgName) ...@@ -486,20 +486,13 @@ def files (pkgName)
end end
def whatprovides (regexPat) def whatprovides (regexPat)
fileArray = [] # Use grep version command to ascertain whether we have a working grep.
needle = regexPat.gsub(/-/,',').gsub(/,/,'\-') unless system('grep -V > /dev/null 2>&1')
Dir[CREW_META_PATH + '*.filelist'].each do |packageList| abort 'Grep is not working. Please install it with \'crew install grep\''.lightred
packageName = File.basename packageList, '.filelist'
File.readlines(packageList).each do |line|
found = line[/#{needle}/] if line.ascii_only?
if found
fileLine = packageName + ': ' + line
unless fileArray.include? fileLine
fileArray.push(fileLine)
end
end
end
end end
fileArray = []
@grepresults = %x[grep "#{regexPat}" #{CREW_META_PATH}*.filelist].chomp.gsub('.filelist','').gsub(':',': ').gsub(CREW_META_PATH,'').split(/$/).map(&:strip)
@grepresults.each { |fileLine| fileArray.push(fileLine) }
unless fileArray.empty? unless fileArray.empty?
fileArray.sort.each do |item| fileArray.sort.each do |item|
puts item puts item
...@@ -1397,7 +1390,7 @@ def upgrade_command(args) ...@@ -1397,7 +1390,7 @@ def upgrade_command(args)
end end
def whatprovides_command(args) def whatprovides_command(args)
args["<name>"].each do |name| args["<pattern>"].each do |name|
whatprovides name whatprovides name
end end
end end
......
# Defines common constants used in different parts of crew # Defines common constants used in different parts of crew
CREW_VERSION = '1.10.4' CREW_VERSION = '1.10.5'
ARCH_ACTUAL = `uname -m`.strip ARCH_ACTUAL = `uname -m`.strip
# This helps with virtualized builds on aarch64 machines # This helps with virtualized builds on aarch64 machines
......
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