2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-14 23:12:17 +02:00
|
|
|
require "cask/artifact/relocated"
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
module Cask
|
2018-09-04 08:45:48 +01:00
|
|
|
class Cmd
|
2020-08-19 10:34:07 +02:00
|
|
|
# Implementation of the `brew cask list` command.
|
|
|
|
#
|
|
|
|
# @api private
|
2017-05-20 19:08:03 +02:00
|
|
|
class List < AbstractCommand
|
2020-08-01 02:30:46 +02:00
|
|
|
def self.description
|
|
|
|
"Lists installed casks or the casks provided in the arguments."
|
2020-07-09 22:58:48 +02:00
|
|
|
end
|
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
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
|
2020-07-09 22:58:48 +02:00
|
|
|
end
|
2017-05-20 03:30:46 +02:00
|
|
|
|
|
|
|
def run
|
2020-08-10 16:16:24 -04:00
|
|
|
self.class.list_casks(
|
|
|
|
*casks,
|
2020-08-01 02:30:46 +02:00
|
|
|
json: args.json?,
|
|
|
|
one: args.public_send(:'1?'),
|
|
|
|
full_name: args.full_name?,
|
|
|
|
versions: args.versions?,
|
2020-08-10 16:16:24 -04:00
|
|
|
)
|
|
|
|
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
|
2020-07-09 22:58:48 +02:00
|
|
|
|
2020-08-10 16:16:24 -04:00
|
|
|
if json
|
2020-07-09 22:58:48 +02:00
|
|
|
puts JSON.generate(output.map(&:to_h))
|
2020-08-10 16:16:24 -04:00
|
|
|
elsif one
|
2020-07-09 22:58:48 +02:00
|
|
|
puts output.map(&:to_s)
|
2020-08-10 16:16:24 -04:00
|
|
|
elsif full_name
|
2020-07-09 22:58:48 +02:00
|
|
|
puts output.map(&:full_name).sort(&tap_and_name_comparison)
|
2020-08-10 16:16:24 -04:00
|
|
|
elsif versions
|
|
|
|
puts output.map(&method(:format_versioned))
|
|
|
|
elsif !output.empty? && casks.any?
|
2020-08-14 23:12:17 +02:00
|
|
|
output.map(&method(:list_artifacts))
|
2020-07-09 22:58:48 +02:00
|
|
|
elsif !output.empty?
|
|
|
|
puts Formatter.columns(output.map(&:to_s))
|
|
|
|
end
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.list_artifacts(cask)
|
2020-08-14 23:12:17 +02:00
|
|
|
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)
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2020-08-14 23:12:17 +02:00
|
|
|
puts artifact
|
|
|
|
end
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.format_versioned(cask)
|
|
|
|
cask.to_s.concat(cask.versions.map(&:to_s).join(" ").prepend(" "))
|
|
|
|
end
|
|
|
|
end
|
2016-09-19 15:15:04 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|