2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-11 17:33:11 +00:00
|
|
|
require "cask_dependent"
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
module Cask
|
2018-09-04 08:45:48 +01:00
|
|
|
class Cmd
|
2021-01-25 09:18:10 +00:00
|
|
|
# Cask implementation of the `brew install` command.
|
2020-08-19 10:34:07 +02:00
|
|
|
#
|
|
|
|
# @api private
|
2017-05-20 19:08:03 +02:00
|
|
|
class Install < AbstractCommand
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2020-09-27 22:53:01 +02:00
|
|
|
OPTIONS = [
|
2022-10-21 23:28:51 -04:00
|
|
|
[:switch, "--adopt", {
|
|
|
|
description: "Adopt existing artifacts in the destination that are identical to those being installed. " \
|
|
|
|
"Cannot be combined with --force.",
|
|
|
|
}],
|
2020-09-27 22:53:01 +02:00
|
|
|
[:switch, "--skip-cask-deps", {
|
|
|
|
description: "Skip installing cask dependencies.",
|
|
|
|
}],
|
2022-04-05 00:57:33 +01:00
|
|
|
[:switch, "--zap", {
|
|
|
|
description: "For use with `brew reinstall --cask`. Remove all files associated with a cask. " \
|
|
|
|
"*May remove files which are shared between applications.*",
|
|
|
|
}],
|
2020-09-27 22:53:01 +02:00
|
|
|
].freeze
|
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
def self.parser(&block)
|
|
|
|
super do
|
|
|
|
switch "--force",
|
|
|
|
description: "Force overwriting existing files."
|
2020-09-27 22:53:01 +02:00
|
|
|
|
2022-10-08 01:08:15 +01:00
|
|
|
OPTIONS.map(&:dup).each do |option|
|
|
|
|
kwargs = option.pop
|
|
|
|
send(*option, **kwargs)
|
2020-09-27 22:53:01 +02:00
|
|
|
end
|
2020-08-01 02:30:46 +02:00
|
|
|
|
2020-11-16 22:18:56 +01:00
|
|
|
instance_eval(&block) if block
|
2020-08-01 02:30:46 +02:00
|
|
|
end
|
2017-05-20 02:27:13 +02:00
|
|
|
end
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { void }
|
2017-05-20 02:27:13 +02:00
|
|
|
def run
|
2020-09-25 21:13:26 +02:00
|
|
|
self.class.install_casks(
|
|
|
|
*casks,
|
2020-08-01 02:30:46 +02:00
|
|
|
binaries: args.binaries?,
|
|
|
|
verbose: args.verbose?,
|
|
|
|
force: args.force?,
|
2022-10-21 23:28:51 -04:00
|
|
|
adopt: args.adopt?,
|
2020-08-01 02:30:46 +02:00
|
|
|
skip_cask_deps: args.skip_cask_deps?,
|
|
|
|
require_sha: args.require_sha?,
|
|
|
|
quarantine: args.quarantine?,
|
2021-09-10 23:11:41 +09:00
|
|
|
quiet: args.quiet?,
|
2022-04-05 00:57:33 +01:00
|
|
|
zap: args.zap?,
|
2020-09-25 21:13:26 +02:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.install_casks(
|
|
|
|
*casks,
|
|
|
|
verbose: nil,
|
|
|
|
force: nil,
|
2022-10-21 23:28:51 -04:00
|
|
|
adopt: nil,
|
2020-09-25 21:13:26 +02:00
|
|
|
binaries: nil,
|
|
|
|
skip_cask_deps: nil,
|
|
|
|
require_sha: nil,
|
2021-09-10 23:11:41 +09:00
|
|
|
quarantine: nil,
|
2022-04-05 00:57:33 +01:00
|
|
|
quiet: nil,
|
2022-08-15 21:48:57 +09:00
|
|
|
zap: nil,
|
|
|
|
dry_run: nil
|
2020-09-25 21:13:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
options = {
|
|
|
|
verbose: verbose,
|
|
|
|
force: force,
|
2022-10-21 23:28:51 -04:00
|
|
|
adopt: adopt,
|
2020-09-25 21:13:26 +02:00
|
|
|
binaries: binaries,
|
|
|
|
skip_cask_deps: skip_cask_deps,
|
|
|
|
require_sha: require_sha,
|
|
|
|
quarantine: quarantine,
|
2022-05-10 19:05:32 +08:00
|
|
|
quiet: quiet,
|
2022-04-05 00:57:33 +01:00
|
|
|
zap: zap,
|
2020-08-01 02:30:46 +02:00
|
|
|
}.compact
|
|
|
|
|
|
|
|
options[:quarantine] = true if options[:quarantine].nil?
|
|
|
|
|
2022-08-17 22:14:05 +09:00
|
|
|
if dry_run
|
2022-08-27 22:29:07 +09:00
|
|
|
if (casks_to_install = casks.reject(&:installed?).presence)
|
2023-02-22 20:59:05 -08:00
|
|
|
plural = ::Utils::Inflection.number(casks_to_install.count, "cask")
|
2022-08-18 00:16:11 +09:00
|
|
|
ohai "Would install #{casks_to_install.count} #{plural}:"
|
2022-08-17 22:14:05 +09:00
|
|
|
puts casks_to_install.map(&:full_name).join(" ")
|
|
|
|
end
|
2022-08-19 21:43:57 +09:00
|
|
|
casks.each do |cask|
|
2022-08-17 22:14:05 +09:00
|
|
|
dep_names = CaskDependent.new(cask)
|
|
|
|
.runtime_dependencies
|
|
|
|
.reject(&:installed?)
|
|
|
|
.map(&:to_formula)
|
|
|
|
.map(&:name)
|
2022-08-19 21:43:57 +09:00
|
|
|
next if dep_names.blank?
|
|
|
|
|
2023-02-22 20:59:05 -08:00
|
|
|
plural = ::Utils::Inflection.number(dep_names.count, "dependenc", "ies", "y")
|
2022-08-19 21:43:57 +09:00
|
|
|
ohai "Would install #{dep_names.count} #{plural} for #{cask.full_name}:"
|
|
|
|
puts dep_names.join(" ")
|
2022-08-17 22:14:05 +09:00
|
|
|
end
|
2022-08-19 21:43:57 +09:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
require "cask/installer"
|
|
|
|
|
|
|
|
casks.each do |cask|
|
2020-08-01 02:30:46 +02:00
|
|
|
Installer.new(cask, **options).install
|
2019-10-13 10:03:26 +01:00
|
|
|
rescue CaskAlreadyInstalledError => e
|
|
|
|
opoo e.message
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|