From e0ff6b1c0e052fa0a7acbcbbe24f3e83c3441e6d Mon Sep 17 00:00:00 2001 From: Maximilian Downey Twiss Date: Tue, 21 May 2024 13:59:15 +1000 Subject: [PATCH] Split whatprovides command into separate file (#9828) --- bin/crew | 22 +++------------------- commands/whatprovides.rb | 22 ++++++++++++++++++++++ lib/const.rb | 4 ++-- 3 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 commands/whatprovides.rb diff --git a/bin/crew b/bin/crew index 120592248..edc03cbfe 100755 --- a/bin/crew +++ b/bin/crew @@ -11,6 +11,7 @@ require_relative '../commands/list' require_relative '../commands/prop' require_relative '../commands/remove' require_relative '../commands/sysinfo' +require_relative '../commands/whatprovides' require_relative '../lib/color' require_relative '../lib/const' require_relative '../lib/crewlog' @@ -279,23 +280,6 @@ def cache_build end end -def whatprovides(regex_pat) - matched_list = `grep -R "#{regex_pat}" #{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 @device[:compatible_packages].any? { |elem| elem[:name] == pkg_name } - pkg_name_status = pkg_name.lightgreen if File.file? "#{CREW_META_PATH}/#{pkg_name}.filelist" - 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 - def update abort "'crew update' is used to update crew itself. Use 'crew upgrade [ ...]' to update specific packages.".orange if @pkg_name @@ -1894,8 +1878,8 @@ def upload_command(args) end def whatprovides_command(args) - args[''].each do |name| - whatprovides name + args[''].each do |regex| + Command.whatprovides(regex) end end diff --git a/commands/whatprovides.rb b/commands/whatprovides.rb new file mode 100644 index 000000000..f7c67304a --- /dev/null +++ b/commands/whatprovides.rb @@ -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 diff --git a/lib/const.rb b/lib/const.rb index 3cbea6594..c98ebf922 100644 --- a/lib/const.rb +++ b/lib/const.rb @@ -2,7 +2,7 @@ # Defines common constants used in different parts of crew require 'etc' -CREW_VERSION = '1.48.1' +CREW_VERSION = '1.48.2' # kernel architecture KERN_ARCH = Etc.uname[:machine] @@ -365,7 +365,7 @@ CREW_DOCOPT = <<~DOCOPT crew update [options] [-v|--verbose] [] crew upgrade [options] [-k|--keep] [-s|--source] [-v|--verbose] [ ...] crew upload [options] [-v|--verbose] [ ...] - crew whatprovides [options] [-v|--verbose] ... + crew whatprovides ... -b --include-build-deps Include build dependencies in output. -t --tree Print dependencies in a tree-structure format.