Split whatprovides command into separate file (#9828)

This commit is contained in:
Maximilian Downey Twiss
2024-05-21 13:59:15 +10:00
committed by GitHub
parent 33dabec87d
commit e0ff6b1c0e
3 changed files with 27 additions and 21 deletions

22
commands/whatprovides.rb Normal file
View File

@@ -0,0 +1,22 @@
require_relative '../lib/const'
require_relative '../lib/package'
require_relative '../lib/package_utils'
class Command
def self.whatprovides(regex)
matched_list = `grep -R "#{regex}" #{CREW_LIB_PATH}/manifest/#{ARCH}`.lines(chomp: true).flat_map do |result|
filelist, matched_file = result.split(':', 2)
pkg_name = File.basename(filelist, '.filelist')
pkg_name_status = pkg_name
if PackageUtils.compatible?(Package.load_package(File.join(CREW_PACKAGES_PATH, "#{pkg_name}.rb")))
pkg_name_status = pkg_name.lightgreen if PackageUtils.installed?(pkg_name)
else
pkg_name_status = pkg_name.lightred
end
"#{pkg_name_status}: #{matched_file}"
end.sort
puts matched_list, "\nTotal found: #{matched_list.length}".lightgreen if matched_list.any?
end
end