Merge pull request #15273 from hyuraku/move-cask/cmd/install
remove `cask/cmd/install`
This commit is contained in:
		
						commit
						7a3376c002
					
				@ -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"
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
@ -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
 | 
			
		||||
@ -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
 | 
			
		||||
@ -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,40 @@ 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?,
 | 
			
		||||
      )
 | 
			
		||||
 | 
			
		||||
      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:     args.quarantine?,
 | 
			
		||||
                            quiet:          args.quiet?).install
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # if the user's flags will prevent bottle only-installations when no
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,6 @@
 | 
			
		||||
require "formula"
 | 
			
		||||
require "keg"
 | 
			
		||||
require "cli/parser"
 | 
			
		||||
require "cask/cmd"
 | 
			
		||||
require "cask/caskroom"
 | 
			
		||||
require "api"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
@ -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
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user