mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
remove cask/cmd
This commit is contained in:
parent
cba118533b
commit
a41a7c94d8
@ -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
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user