Files
chromebrew/commands/list.rb
Maximilian Downey Twiss 33901368d7 Enable more rubocop cops (#9980)
* Remove self.check in python3.rb as tests were not actuallly being run

* Enable Lint/ImplicitStringConcatenation cop

* Enable Layout/CommentIndentation cop

* Remove unnecessary configuration of Layout/IndentationStyle to EnforcedStyle: spaces, as this is already the default

* Enable Layout/LeadingCommentSpace cop

* Enable Layout/SpaceInsideBlockBraces cop

* Enable Layout/SpaceInsideParens cop

* Enable Layout/TrailingEmptyLines cop

* Enable Lint/LiteralAsCondition cop

* Document the current issue stopping us from enabling Style/OptionalBooleanParameter

* Stop downloading our rubocop config when installing ruby_rubocop
2024-06-17 16:19:11 -04:00

52 lines
1.9 KiB
Ruby

require 'fileutils'
require 'json'
require_relative '../lib/color'
require_relative '../lib/const'
require_relative '../lib/package'
require_relative '../lib/package_utils'
class Command
def self.list(available, installed, compatible, incompatible, verbose)
device_json = JSON.load_file(File.join(CREW_CONFIG_PATH, 'device.json'), symbolize_names: true)
installed_packages = {}
device_json[:installed_packages].each do |package|
installed_packages[package[:name]] = package[:version]
end
if available
Dir["#{CREW_PACKAGES_PATH}/*.rb"].each do |filename|
pkg_name = File.basename(filename, '.rb')
next if installed_packages.key?(pkg_name)
pkg = Package.load_package(filename)
puts pkg_name if PackageUtils.compatible?(pkg)
end
elsif installed
if verbose
installed_packages['======='] = '======='
installed_packages['Package'] = 'Version'
first_col_width = installed_packages.keys.max { |a, b| a.size <=> b.size }.size
installed_packages.sort.to_h.each do |package, version|
puts "#{package.ljust(first_col_width)} #{version}".lightgreen
end
else
installed_packages.each_key do |package|
puts package.lightgreen
end
end
elsif compatible
Dir["#{CREW_PACKAGES_PATH}/*.rb"].each do |filename|
pkg_name = File.basename(filename, '.rb')
pkg = Package.load_package(filename)
puts pkg_name.lightgreen if PackageUtils.compatible?(pkg) && installed_packages.key?(pkg_name)
puts pkg_name if PackageUtils.compatible?(pkg)
end
elsif incompatible
Dir["#{CREW_PACKAGES_PATH}/*.rb"].each do |filename|
pkg_name = File.basename(filename, '.rb')
pkg = Package.load_package(filename)
puts pkg_name.lightred unless PackageUtils.compatible?(pkg)
end
end
end
end