From cba118533b83ba1587cf65da0142f58523d210e7 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 19 Apr 2023 21:06:27 +0900 Subject: [PATCH 1/4] remove cask/cmd specs --- .../Homebrew/test/cask/cmd/install_spec.rb | 131 ---------- Library/Homebrew/test/cask/quarantine_spec.rb | 227 ------------------ 2 files changed, 358 deletions(-) delete mode 100644 Library/Homebrew/test/cask/cmd/install_spec.rb delete mode 100644 Library/Homebrew/test/cask/quarantine_spec.rb diff --git a/Library/Homebrew/test/cask/cmd/install_spec.rb b/Library/Homebrew/test/cask/cmd/install_spec.rb deleted file mode 100644 index 19a2a1cf1a..0000000000 --- a/Library/Homebrew/test/cask/cmd/install_spec.rb +++ /dev/null @@ -1,131 +0,0 @@ -# typed: false -# frozen_string_literal: true - -describe Cask::Cmd::Install, :cask do - it "displays the installation progress" do - output = Regexp.new <<~EOS - ==> Downloading file:.*caffeine.zip - ==> Installing Cask local-caffeine - ==> Moving App 'Caffeine.app' to '.*Caffeine.app' - .*local-caffeine was successfully installed! - EOS - - expect do - described_class.run("local-caffeine") - end.to output(output).to_stdout - end - - it "allows staging and activation of multiple Casks at once" do - described_class.run("local-transmission", "local-caffeine") - transmission = Cask::CaskLoader.load(cask_path("local-transmission")) - caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) - expect(transmission).to be_installed - expect(transmission.config.appdir.join("Transmission.app")).to be_a_directory - expect(caffeine).to be_installed - expect(caffeine.config.appdir.join("Caffeine.app")).to be_a_directory - end - - it "recognizes the --appdir flag" do - appdir = mktmpdir - - expect(Cask::CaskLoader).to receive(:load) - .with("local-caffeine", any_args) - .and_wrap_original { |f, *args| - caffeine = f.call(*args) - expect(caffeine.config.appdir).to eq appdir - caffeine - } - - described_class.run("local-caffeine", "--appdir=#{appdir}") - end - - it "recognizes the --appdir flag from HOMEBREW_CASK_OPTS" do - appdir = mktmpdir - - expect(Cask::CaskLoader).to receive(:load) - .with("local-caffeine", any_args) - .and_wrap_original { |f, *args| - caffeine = f.call(*args) - expect(caffeine.config.appdir).to eq appdir - caffeine - } - - ENV["HOMEBREW_CASK_OPTS"] = "--appdir=#{appdir}" - - described_class.run("local-caffeine") - end - - it "prefers an explicit --appdir flag to one from HOMEBREW_CASK_OPTS" do - global_appdir = mktmpdir - appdir = mktmpdir - - expect(Cask::CaskLoader).to receive(:load) - .with("local-caffeine", any_args) - .and_wrap_original { |f, *args| - caffeine = f.call(*args) - expect(caffeine.config.appdir).to eq appdir - caffeine - } - - ENV["HOMEBREW_CASK_OPTS"] = "--appdir=#{global_appdir}" - - described_class.run("local-caffeine", "--appdir=#{appdir}") - end - - it "skips double install (without nuking existing installation)" do - described_class.run("local-transmission") - described_class.run("local-transmission") - expect(Cask::CaskLoader.load(cask_path("local-transmission"))).to be_installed - end - - it "prints a warning message on double install" do - described_class.run("local-transmission") - - expect do - described_class.run("local-transmission") - end.to output(/Warning: Cask 'local-transmission' is already installed./).to_stderr - end - - it "allows double install with --force" do - described_class.run("local-transmission") - - expect do - expect do - described_class.run("local-transmission", "--force") - end.to output(/It seems there is already an App at.*overwriting\./).to_stderr - end.to output(/local-transmission was successfully installed!/).to_stdout - end - - it "skips dependencies with --skip-cask-deps" do - described_class.run("with-depends-on-cask-multiple", "--skip-cask-deps") - expect(Cask::CaskLoader.load(cask_path("with-depends-on-cask-multiple"))).to be_installed - expect(Cask::CaskLoader.load(cask_path("local-caffeine"))).not_to be_installed - expect(Cask::CaskLoader.load(cask_path("local-transmission"))).not_to be_installed - end - - it "properly handles Casks that are not present" do - expect do - described_class.run("notacask") - end.to raise_error(Cask::CaskUnavailableError) - end - - it "returns a suggestion for a misspelled Cask" do - expect do - described_class.run("localcaffeine") - end.to raise_error( - Cask::CaskUnavailableError, - "Cask 'localcaffeine' is unavailable: No Cask with this name exists. " \ - "Did you mean 'local-caffeine'?", - ) - end - - it "returns multiple suggestions for a Cask fragment" do - expect do - described_class.run("local") - end.to raise_error( - Cask::CaskUnavailableError, - "Cask 'local' is unavailable: No Cask with this name exists. " \ - "Did you mean one of these?\nlocal-caffeine\nlocal-transmission\n", - ) - end -end diff --git a/Library/Homebrew/test/cask/quarantine_spec.rb b/Library/Homebrew/test/cask/quarantine_spec.rb deleted file mode 100644 index d08872fff6..0000000000 --- a/Library/Homebrew/test/cask/quarantine_spec.rb +++ /dev/null @@ -1,227 +0,0 @@ -# typed: false -# frozen_string_literal: true - -require "cask/cmd/install" -require "cask/cask_loader" -require "cask/download" -require "cask/quarantine" - -describe Cask::Quarantine, :cask do - matcher :be_quarantined do - match do |path| - expect( - described_class.detect(path), - ).to be true - end - end - - describe "by default" do - it "quarantines a nice fresh Cask" do - Cask::Cmd::Install.run("local-transmission") - - cask = Cask::CaskLoader.load(cask_path("local-transmission")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("Transmission.app")).to be_quarantined - end - - it "quarantines Cask fetches" do - download = Cask::Download.new(Cask::CaskLoader.load("local-transmission"), quarantine: true) - download.fetch - local_transmission = Cask::CaskLoader.load(cask_path("local-transmission")) - cached_location = Cask::Download.new(local_transmission).fetch - - expect(cached_location).to be_quarantined - end - - it "quarantines Cask installs even if the fetch was not" do - download = Cask::Download.new(Cask::CaskLoader.load("local-transmission"), quarantine: false) - download.fetch - - Cask::Cmd::Install.run("local-transmission") - - cask = Cask::CaskLoader.load(cask_path("local-transmission")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("Transmission.app")).to be_quarantined - end - - it "quarantines dmg-based Casks" do - Cask::Cmd::Install.run("container-dmg") - - cask = Cask::CaskLoader.load(cask_path("container-dmg")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).to be_quarantined - end - - it "quarantines tar-gz-based Casks" do - Cask::Cmd::Install.run("container-tar-gz") - - cask = Cask::CaskLoader.load(cask_path("container-tar-gz")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).to be_quarantined - end - - it "quarantines xar-based Casks" do - Cask::Cmd::Install.run("container-xar") - - cask = Cask::CaskLoader.load(cask_path("container-xar")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).to be_quarantined - end - - it "quarantines pure bzip2-based Casks" do - Cask::Cmd::Install.run("container-bzip2") - - cask = Cask::CaskLoader.load(cask_path("container-bzip2")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).to be_quarantined - end - - it "quarantines pure gzip-based Casks" do - Cask::Cmd::Install.run("container-gzip") - - cask = Cask::CaskLoader.load(cask_path("container-gzip")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).to be_quarantined - end - - it "quarantines the pkg in naked-pkg-based Casks" do - Cask::Cmd::Install.run("container-pkg") - - cask = Cask::CaskLoader.load(cask_path("container-pkg")) - - expect(cask).to be_installed - - expect(cask.staged_path/"container.pkg").to be_quarantined - end - - it "quarantines a nested container" do - Cask::Cmd::Install.run("nested-app") - - cask = Cask::CaskLoader.load(cask_path("nested-app")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("MyNestedApp.app")).to be_quarantined - end - end - - describe "when disabled" do - it "does not quarantine even a nice, fresh Cask" do - Cask::Cmd::Install.run("local-transmission", "--no-quarantine") - - cask = Cask::CaskLoader.load(cask_path("local-transmission")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("Transmission.app")).not_to be_quarantined - end - - it "does not quarantine Cask fetches" do - download = Cask::Download.new(Cask::CaskLoader.load("local-transmission"), quarantine: false) - download.fetch - local_transmission = Cask::CaskLoader.load(cask_path("local-transmission")) - cached_location = Cask::Download.new(local_transmission).fetch - - expect(cached_location).not_to be_quarantined - end - - it "does not quarantine Cask installs even if the fetch was" do - download = Cask::Download.new(Cask::CaskLoader.load("local-transmission"), quarantine: true) - download.fetch - - Cask::Cmd::Install.run("local-transmission", "--no-quarantine") - - cask = Cask::CaskLoader.load(cask_path("local-transmission")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("Transmission.app")).not_to be_quarantined - end - - it "does not quarantine dmg-based Casks" do - Cask::Cmd::Install.run("container-dmg", "--no-quarantine") - - cask = Cask::CaskLoader.load(cask_path("container-dmg")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).not_to be_quarantined - end - - it "does not quarantine tar-gz-based Casks" do - Cask::Cmd::Install.run("container-tar-gz", "--no-quarantine") - - cask = Cask::CaskLoader.load(cask_path("container-tar-gz")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).not_to be_quarantined - end - - it "does not quarantine xar-based Casks" do - Cask::Cmd::Install.run("container-xar", "--no-quarantine") - - cask = Cask::CaskLoader.load(cask_path("container-xar")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).not_to be_quarantined - end - - it "does not quarantine pure bzip2-based Casks" do - Cask::Cmd::Install.run("container-bzip2", "--no-quarantine") - - cask = Cask::CaskLoader.load(cask_path("container-bzip2")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).not_to be_quarantined - end - - it "does not quarantine pure gzip-based Casks" do - Cask::Cmd::Install.run("container-gzip", "--no-quarantine") - - cask = Cask::CaskLoader.load(cask_path("container-gzip")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("container")).not_to be_quarantined - end - - it "does not quarantine the pkg in naked-pkg-based Casks" do - Cask::Cmd::Install.run("container-pkg", "--no-quarantine") - - naked_pkg = Cask::CaskLoader.load(cask_path("container-pkg")) - - expect(naked_pkg).to be_installed - - expect( - Cask::Caskroom.path.join("container-pkg", naked_pkg.version, "container.pkg"), - ).not_to be_quarantined - end - - it "does not quarantine a nested container" do - Cask::Cmd::Install.run("nested-app", "--no-quarantine") - - cask = Cask::CaskLoader.load(cask_path("nested-app")) - - expect(cask).to be_installed - - expect(cask.config.appdir.join("MyNestedApp.app")).not_to be_quarantined - end - end -end From a41a7c94d81f4a67ab9fc9afb37ac6d08303d134 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 19 Apr 2023 21:30:42 +0900 Subject: [PATCH 2/4] remove cask/cmd --- Library/Homebrew/cask.rb | 1 - Library/Homebrew/cask/cmd.rb | 32 ----- Library/Homebrew/cask/cmd/abstract_command.rb | 98 --------------- Library/Homebrew/cask/cmd/install.rb | 116 ------------------ Library/Homebrew/cmd/outdated.rb | 1 - Library/Homebrew/cmd/reinstall.rb | 26 +++- Library/Homebrew/cmd/upgrade.rb | 14 ++- .../Homebrew/extend/os/mac/missing_formula.rb | 1 - 8 files changed, 35 insertions(+), 254 deletions(-) delete mode 100644 Library/Homebrew/cask/cmd.rb delete mode 100644 Library/Homebrew/cask/cmd/abstract_command.rb delete mode 100644 Library/Homebrew/cask/cmd/install.rb diff --git a/Library/Homebrew/cask.rb b/Library/Homebrew/cask.rb index 2f9df69d02..d3e6d8ebae 100644 --- a/Library/Homebrew/cask.rb +++ b/Library/Homebrew/cask.rb @@ -8,7 +8,6 @@ require "cask/cache" require "cask/cask_loader" require "cask/cask" require "cask/caskroom" -require "cask/cmd" require "cask/config" require "cask/exceptions" require "cask/denylist" diff --git a/Library/Homebrew/cask/cmd.rb b/Library/Homebrew/cask/cmd.rb deleted file mode 100644 index b2db671417..0000000000 --- a/Library/Homebrew/cask/cmd.rb +++ /dev/null @@ -1,32 +0,0 @@ -# typed: true -# frozen_string_literal: true - -require "optparse" -require "shellwords" - -require "cli/parser" -require "extend/optparse" - -require "cask/config" - -require "cask/cmd/abstract_command" -require "cask/cmd/install" - -module Cask - # Implementation of the `brew cask` command-line interface. - # - # @api private - class Cmd - extend T::Sig - - include Context - - def self.parser(&block) - Homebrew::CLI::Parser.new do - instance_eval(&block) if block - - cask_options - end - end - end -end diff --git a/Library/Homebrew/cask/cmd/abstract_command.rb b/Library/Homebrew/cask/cmd/abstract_command.rb deleted file mode 100644 index 23e972087c..0000000000 --- a/Library/Homebrew/cask/cmd/abstract_command.rb +++ /dev/null @@ -1,98 +0,0 @@ -# typed: false -# frozen_string_literal: true - -require "search" - -module Cask - class Cmd - # Abstract superclass for all Cask implementations of commands. - # - # @api private - class AbstractCommand - extend T::Sig - extend T::Helpers - - OPTIONS = [ - [:switch, "--[no-]binaries", { - description: "Disable/enable linking of helper executables (default: enabled).", - env: :cask_opts_binaries, - }], - [:switch, "--require-sha", { - description: "Require all casks to have a checksum.", - env: :cask_opts_require_sha, - }], - [:switch, "--[no-]quarantine", { - description: "Disable/enable quarantining of downloads (default: enabled).", - env: :cask_opts_quarantine, - }], - ].freeze - - def self.parser(&block) - Cmd.parser do - instance_eval(&block) if block - - OPTIONS.map(&:dup).each do |option| - kwargs = option.pop - send(*option, **kwargs) - end - end - end - - sig { returns(String) } - def self.command_name - @command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase - end - - sig { returns(T::Boolean) } - def self.abstract? - name.split("::").last.match?(/^Abstract[^a-z]/) - end - - sig { returns(T::Boolean) } - def self.visible? - true - end - - sig { returns(String) } - def self.help - parser.generate_help_text - end - - sig { returns(String) } - def self.short_description - description[/\A[^.]*\./] - end - - def self.run(*args) - new(*args).run - end - - attr_reader :args - - def initialize(*args) - @args = self.class.parser.parse(args) - end - - private - - def casks(alternative: -> { [] }) - return @casks if defined?(@casks) - - @casks = args.named.empty? ? alternative.call : args.named.to_casks - rescue CaskUnavailableError => e - reason = [e.reason, *suggestion_message(e.token)].join(" ") - raise e.class.new(e.token, reason) - end - - def suggestion_message(cask_token) - matches = Homebrew::Search.search_casks(cask_token) - - if matches.one? - "Did you mean '#{matches.first}'?" - elsif !matches.empty? - "Did you mean one of these?\n#{Formatter.columns(matches.take(20))}" - end - end - end - end -end diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb deleted file mode 100644 index c4cbab03ef..0000000000 --- a/Library/Homebrew/cask/cmd/install.rb +++ /dev/null @@ -1,116 +0,0 @@ -# typed: false -# frozen_string_literal: true - -require "cask_dependent" - -module Cask - class Cmd - # Cask implementation of the `brew install` command. - # - # @api private - class Install < AbstractCommand - extend T::Sig - - OPTIONS = [ - [:switch, "--adopt", { - description: "Adopt existing artifacts in the destination that are identical to those being installed. " \ - "Cannot be combined with --force.", - }], - [:switch, "--skip-cask-deps", { - description: "Skip installing cask dependencies.", - }], - [:switch, "--zap", { - description: "For use with `brew reinstall --cask`. Remove all files associated with a cask. " \ - "*May remove files which are shared between applications.*", - }], - ].freeze - - def self.parser(&block) - super do - switch "--force", - description: "Force overwriting existing files." - - OPTIONS.map(&:dup).each do |option| - kwargs = option.pop - send(*option, **kwargs) - end - - instance_eval(&block) if block - end - end - - sig { void } - def run - self.class.install_casks( - *casks, - binaries: args.binaries?, - verbose: args.verbose?, - force: args.force?, - adopt: args.adopt?, - skip_cask_deps: args.skip_cask_deps?, - require_sha: args.require_sha?, - quarantine: args.quarantine?, - quiet: args.quiet?, - zap: args.zap?, - ) - end - - def self.install_casks( - *casks, - verbose: nil, - force: nil, - adopt: nil, - binaries: nil, - skip_cask_deps: nil, - require_sha: nil, - quarantine: nil, - quiet: nil, - zap: nil, - dry_run: nil - ) - - options = { - verbose: verbose, - force: force, - adopt: adopt, - binaries: binaries, - skip_cask_deps: skip_cask_deps, - require_sha: require_sha, - quarantine: quarantine, - quiet: quiet, - zap: zap, - }.compact - - options[:quarantine] = true if options[:quarantine].nil? - - if dry_run - if (casks_to_install = casks.reject(&:installed?).presence) - ohai "Would install #{::Utils.pluralize("cask", casks_to_install.count, include_count: true)}:" - puts casks_to_install.map(&:full_name).join(" ") - end - casks.each do |cask| - dep_names = CaskDependent.new(cask) - .runtime_dependencies - .reject(&:installed?) - .map(&:to_formula) - .map(&:name) - next if dep_names.blank? - - ohai "Would install #{::Utils.pluralize("dependenc", dep_names.count, plural: "ies", singular: "y", - include_count: true)} for #{cask.full_name}:" - puts dep_names.join(" ") - end - return - end - - require "cask/installer" - - casks.each do |cask| - Installer.new(cask, **options).install - rescue CaskAlreadyInstalledError => e - opoo e.message - end - end - end - end -end diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb index becc267a2d..677d2d6878 100644 --- a/Library/Homebrew/cmd/outdated.rb +++ b/Library/Homebrew/cmd/outdated.rb @@ -4,7 +4,6 @@ require "formula" require "keg" require "cli/parser" -require "cask/cmd" require "cask/caskroom" require "api" diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 507dbb61d6..1aa5c77e51 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -8,7 +8,6 @@ require "install" require "reinstall" require "cli/parser" require "cleanup" -require "cask/cmd" require "cask/utils" require "cask/macos" require "cask/reinstall" @@ -75,8 +74,29 @@ module Homebrew formula_options [ [:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }], - *Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup), - *Cask::Cmd::Install::OPTIONS.map(&:dup), + [:switch, "--[no-]binaries", { + description: "Disable/enable linking of helper executables (default: enabled).", + env: :cask_opts_binaries, + }], + [:switch, "--require-sha", { + description: "Require all casks to have a checksum.", + env: :cask_opts_require_sha, + }], + [:switch, "--[no-]quarantine", { + description: "Disable/enable quarantining of downloads (default: enabled).", + env: :cask_opts_quarantine, + }], + [:switch, "--adopt", { + description: "Adopt existing artifacts in the destination that are identical to those being installed. " \ + "Cannot be combined with --force.", + }], + [:switch, "--skip-cask-deps", { + description: "Skip installing cask dependencies.", + }], + [:switch, "--zap", { + description: "For use with `brew reinstall --cask`. Remove all files associated with a cask. " \ + "*May remove files which are shared between applications.*", + }], ].each do |args| options = args.pop send(*args, **options) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 0146f38aae..c30792e1c3 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -5,7 +5,6 @@ require "cli/parser" require "formula_installer" require "install" require "upgrade" -require "cask/cmd" require "cask/utils" require "cask/upgrade" require "cask/macos" @@ -100,7 +99,18 @@ module Homebrew [:switch, "--greedy-auto-updates", { description: "Also include casks with `auto_updates true`.", }], - *Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup), + [:switch, "--[no-]binaries", { + description: "Disable/enable linking of helper executables (default: enabled).", + env: :cask_opts_binaries, + }], + [:switch, "--require-sha", { + description: "Require all casks to have a checksum.", + env: :cask_opts_require_sha, + }], + [:switch, "--[no-]quarantine", { + description: "Disable/enable quarantining of downloads (default: enabled).", + env: :cask_opts_quarantine, + }], ].each do |args| options = args.pop send(*args, **options) diff --git a/Library/Homebrew/extend/os/mac/missing_formula.rb b/Library/Homebrew/extend/os/mac/missing_formula.rb index 681747e88b..c7f7e701ed 100644 --- a/Library/Homebrew/extend/os/mac/missing_formula.rb +++ b/Library/Homebrew/extend/os/mac/missing_formula.rb @@ -1,7 +1,6 @@ # typed: strict # frozen_string_literal: true -require "cask/cmd/abstract_command" require "cask/info" require "cask/cask_loader" require "cask/caskroom" From b2156dc1252d4ece02e167ab36eb17459d5c5edf Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 19 Apr 2023 21:31:22 +0900 Subject: [PATCH 3/4] add casks install to cmd/install --- Library/Homebrew/cmd/install.rb | 76 +++++++++++++++----- Library/Homebrew/test/cask/reinstall_spec.rb | 2 +- Library/Homebrew/test/cask/upgrade_spec.rb | 8 +-- 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 99dc96c56a..d539e794d8 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -2,8 +2,8 @@ # frozen_string_literal: true require "cask/config" -require "cask/cmd" -require "cask/cmd/install" +require "cask/installer" +require "cask_dependent" require "missing_formula" require "formula_installer" require "development_tools" @@ -127,8 +127,29 @@ module Homebrew formula_options [ [:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }], - *Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup), - *Cask::Cmd::Install::OPTIONS.map(&:dup), + [:switch, "--[no-]binaries", { + description: "Disable/enable linking of helper executables (default: enabled).", + env: :cask_opts_binaries, + }], + [:switch, "--require-sha", { + description: "Require all casks to have a checksum.", + env: :cask_opts_require_sha, + }], + [:switch, "--[no-]quarantine", { + description: "Disable/enable quarantining of downloads (default: enabled).", + env: :cask_opts_quarantine, + }], + [:switch, "--adopt", { + description: "Adopt existing artifacts in the destination that are identical to those being installed. " \ + "Cannot be combined with --force.", + }], + [:switch, "--skip-cask-deps", { + description: "Skip installing cask dependencies.", + }], + [:switch, "--zap", { + description: "For use with `brew reinstall --cask`. Remove all files associated with a cask. " \ + "*May remove files which are shared between applications.*", + }], ].each do |args| options = args.pop send(*args, **options) @@ -183,18 +204,41 @@ module Homebrew end if casks.any? - Cask::Cmd::Install.install_casks( - *casks, - binaries: args.binaries?, - verbose: args.verbose?, - force: args.force?, - adopt: args.adopt?, - require_sha: args.require_sha?, - skip_cask_deps: args.skip_cask_deps?, - quarantine: args.quarantine?, - quiet: args.quiet?, - dry_run: args.dry_run?, - ) + quarantine = args.quarantine?.nil? ? true : args.quarantine? + + if args.dry_run? + if (casks_to_install = casks.reject(&:installed?).presence) + ohai "Would install #{::Utils.pluralize("cask", casks_to_install.count, include_count: true)}:" + puts casks_to_install.map(&:full_name).join(" ") + end + casks.each do |cask| + dep_names = CaskDependent.new(cask) + .runtime_dependencies + .reject(&:installed?) + .map(&:to_formula) + .map(&:name) + next if dep_names.blank? + + ohai "Would install #{::Utils.pluralize("dependenc", dep_names.count, plural: "ies", singular: "y", + include_count: true)} for #{cask.full_name}:" + puts dep_names.join(" ") + end + return + end + + require "cask/installer" + + casks.each do |cask| + Cask::Installer.new(cask, + binaries: args.binaries?, + verbose: args.verbose?, + force: args.force?, + adopt: args.adopt?, + require_sha: args.require_sha?, + skip_cask_deps: args.skip_cask_deps?, + quarantine: quarantine, + quiet: args.quiet?).install + end end # if the user's flags will prevent bottle only-installations when no diff --git a/Library/Homebrew/test/cask/reinstall_spec.rb b/Library/Homebrew/test/cask/reinstall_spec.rb index 1a7d8ee8ad..c253eae3fa 100644 --- a/Library/Homebrew/test/cask/reinstall_spec.rb +++ b/Library/Homebrew/test/cask/reinstall_spec.rb @@ -53,7 +53,7 @@ describe Cask::Reinstall, :cask do end it "allows reinstalling a Cask" do - Cask::Cmd::Install.run("local-transmission") + Cask::Installer.new(Cask::CaskLoader.load(cask_path("local-transmission"))).install expect(Cask::CaskLoader.load(cask_path("local-transmission"))).to be_installed diff --git a/Library/Homebrew/test/cask/upgrade_spec.rb b/Library/Homebrew/test/cask/upgrade_spec.rb index 5647f3eceb..c2ad68350e 100644 --- a/Library/Homebrew/test/cask/upgrade_spec.rb +++ b/Library/Homebrew/test/cask/upgrade_spec.rb @@ -26,7 +26,7 @@ describe Cask::Upgrade, :cask do end before do - installed.each { |cask| Cask::Cmd::Install.run(cask) } + installed.each { |cask| Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install } allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) end @@ -191,7 +191,7 @@ describe Cask::Upgrade, :cask do end before do - installed.each { |cask| Cask::Cmd::Install.run(cask) } + installed.each { |cask| Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install } allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) end @@ -358,7 +358,7 @@ describe Cask::Upgrade, :cask do end before do - installed.each { |cask| Cask::Cmd::Install.run(cask) } + installed.each { |cask| Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install } allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) end @@ -414,7 +414,7 @@ describe Cask::Upgrade, :cask do end before do - installed.each { |cask| Cask::Cmd::Install.run(cask) } + installed.each { |cask| Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install } allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) end From c46ee85e0a992fffd555e546c5c1aa911619b4e0 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 19 Apr 2023 23:15:12 +0900 Subject: [PATCH 4/4] remove args.quarantine? nil check --- Library/Homebrew/cmd/install.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index d539e794d8..10c60c31eb 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -204,7 +204,6 @@ module Homebrew end if casks.any? - quarantine = args.quarantine?.nil? ? true : args.quarantine? if args.dry_run? if (casks_to_install = casks.reject(&:installed?).presence) @@ -236,7 +235,7 @@ module Homebrew adopt: args.adopt?, require_sha: args.require_sha?, skip_cask_deps: args.skip_cask_deps?, - quarantine: quarantine, + quarantine: args.quarantine?, quiet: args.quiet?).install end end