From e39232313fd3256a516a4a1fb6769ccb72c32da3 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 1 Mar 2023 21:22:11 +0900 Subject: [PATCH] move cask/cmd/list to cask/list --- Library/Homebrew/cask/cmd.rb | 1 - Library/Homebrew/cask/cmd/list.rb | 81 ------------------------------- Library/Homebrew/cask/list.rb | 50 +++++++++++++++++++ Library/Homebrew/cmd/list.rb | 4 +- 4 files changed, 52 insertions(+), 84 deletions(-) delete mode 100644 Library/Homebrew/cask/cmd/list.rb create mode 100644 Library/Homebrew/cask/list.rb diff --git a/Library/Homebrew/cask/cmd.rb b/Library/Homebrew/cask/cmd.rb index 0ab2baf3d4..7981202af0 100644 --- a/Library/Homebrew/cask/cmd.rb +++ b/Library/Homebrew/cask/cmd.rb @@ -13,7 +13,6 @@ require "cask/cmd/abstract_command" require "cask/cmd/audit" require "cask/cmd/fetch" require "cask/cmd/install" -require "cask/cmd/list" require "cask/cmd/reinstall" require "cask/cmd/uninstall" require "cask/cmd/upgrade" diff --git a/Library/Homebrew/cask/cmd/list.rb b/Library/Homebrew/cask/cmd/list.rb deleted file mode 100644 index e38b994d0e..0000000000 --- a/Library/Homebrew/cask/cmd/list.rb +++ /dev/null @@ -1,81 +0,0 @@ -# typed: false -# frozen_string_literal: true - -require "cask/artifact/relocated" - -module Cask - class Cmd - # Cask implementation of the `brew list` command. - # - # @api private - class List < AbstractCommand - extend T::Sig - - def self.parser - super do - switch "-1", - description: "Force output to be one entry per line." - switch "--versions", - description: "Show the version number the listed casks." - switch "--full-name", - description: "Print casks with fully-qualified names." - switch "--json", - description: "Print a JSON representation of the listed casks. " - end - end - - sig { void } - def run - self.class.list_casks( - *casks, - json: args.json?, - one: args.public_send(:"1?"), - full_name: args.full_name?, - versions: args.versions?, - ) - end - - def self.list_casks(*casks, json: false, one: false, full_name: false, versions: false) - output = if casks.any? - casks.each do |cask| - raise CaskNotInstalledError, cask unless cask.installed? - end - else - Caskroom.casks - end - - if json - puts JSON.pretty_generate(output.map(&:to_h)) - elsif one - puts output.map(&:to_s) - elsif full_name - puts output.map(&:full_name).sort(&tap_and_name_comparison) - elsif versions - puts output.map(&method(:format_versioned)) - elsif !output.empty? && casks.any? - output.map(&method(:list_artifacts)) - elsif !output.empty? - puts Formatter.columns(output.map(&:to_s)) - end - end - - def self.list_artifacts(cask) - cask.artifacts.group_by(&:class).sort_by { |klass, _| klass.english_name }.each do |klass, artifacts| - next if [Artifact::Uninstall, Artifact::Zap].include? klass - - ohai klass.english_name - artifacts.each do |artifact| - puts artifact.summarize_installed if artifact.respond_to?(:summarize_installed) - next if artifact.respond_to?(:summarize_installed) - - puts artifact - end - end - end - - def self.format_versioned(cask) - cask.to_s.concat(cask.versions.map(&:to_s).join(" ").prepend(" ")) - end - end - end -end diff --git a/Library/Homebrew/cask/list.rb b/Library/Homebrew/cask/list.rb new file mode 100644 index 0000000000..8a8a5b7ebf --- /dev/null +++ b/Library/Homebrew/cask/list.rb @@ -0,0 +1,50 @@ +# typed: false +# frozen_string_literal: true + +require "cask/artifact/relocated" + +module Cask + # @api private + class List + + def self.list_casks(*casks, one: false, full_name: false, versions: false) + output = if casks.any? + casks.each do |cask| + raise CaskNotInstalledError, cask unless cask.installed? + end + else + Caskroom.casks + end + + if one + puts output.map(&:to_s) + elsif full_name + puts output.map(&:full_name).sort(&tap_and_name_comparison) + elsif versions + puts output.map(&method(:format_versioned)) + elsif !output.empty? && casks.any? + output.map(&method(:list_artifacts)) + elsif !output.empty? + puts Formatter.columns(output.map(&:to_s)) + end + end + + def self.list_artifacts(cask) + cask.artifacts.group_by(&:class).sort_by { |klass, _| klass.english_name }.each do |klass, artifacts| + next if [Artifact::Uninstall, Artifact::Zap].include? klass + + ohai klass.english_name + artifacts.each do |artifact| + puts artifact.summarize_installed if artifact.respond_to?(:summarize_installed) + next if artifact.respond_to?(:summarize_installed) + + puts artifact + end + end + end + + def self.format_versioned(cask) + cask.to_s.concat(cask.versions.map(&:to_s).join(" ").prepend(" ")) + end + end +end diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 9de67b45eb..2bab5bd361 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -4,7 +4,7 @@ require "metafiles" require "formula" require "cli/parser" -require "cask/cmd" +require "cask/list" module Homebrew extend T::Sig @@ -164,7 +164,7 @@ module Homebrew end return if casks.blank? - Cask::Cmd::List.list_casks( + Cask::List.list_casks( *casks, one: args.public_send(:"1?"), full_name: args.full_name?,