Add cask options to brew reinstall
.
This commit is contained in:
parent
16d5596fbd
commit
e40eece17b
@ -23,21 +23,33 @@ module Homebrew
|
|||||||
super(@args)
|
super(@args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_casks
|
||||||
|
@to_casks ||= to_formulae_and_casks(only: :cask).freeze
|
||||||
|
end
|
||||||
|
|
||||||
def to_formulae
|
def to_formulae
|
||||||
@to_formulae ||= to_formulae_and_casks(only: :formula).freeze
|
@to_formulae ||= to_formulae_and_casks(only: :formula).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_formulae_and_casks(only: nil)
|
def to_formulae_and_casks(only: nil, method: nil)
|
||||||
@to_formulae_and_casks ||= {}
|
@to_formulae_and_casks ||= {}
|
||||||
@to_formulae_and_casks[only] ||= begin
|
@to_formulae_and_casks[only] ||= begin
|
||||||
to_objects(only: only).reject { |o| o.is_a?(Tap) }.freeze
|
to_objects(only: only, method: method).reject { |o| o.is_a?(Tap) }.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_formula_or_cask(name, only: nil)
|
def load_formula_or_cask(name, only: nil, method: nil)
|
||||||
if only != :cask
|
if only != :cask
|
||||||
begin
|
begin
|
||||||
formula = Formulary.factory(name, spec, force_bottle: @force_bottle, flags: @flags)
|
formula = case method
|
||||||
|
when nil, :factory
|
||||||
|
Formulary.factory(name, *spec, force_bottle: @force_bottle, flags: @flags)
|
||||||
|
when :resolve
|
||||||
|
Formulary.resolve(name, spec: spec, force_bottle: @force_bottle, flags: @flags)
|
||||||
|
else
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
|
||||||
warn_if_cask_conflicts(name, "formula") unless only == :formula
|
warn_if_cask_conflicts(name, "formula") unless only == :formula
|
||||||
return formula
|
return formula
|
||||||
rescue FormulaUnavailableError => e
|
rescue FormulaUnavailableError => e
|
||||||
@ -47,7 +59,7 @@ module Homebrew
|
|||||||
|
|
||||||
if only != :formula
|
if only != :formula
|
||||||
begin
|
begin
|
||||||
return Cask::CaskLoader.load(name)
|
return Cask::CaskLoader.load(name, config: Cask::Config.from_args(@parent))
|
||||||
rescue Cask::CaskUnavailableError
|
rescue Cask::CaskUnavailableError
|
||||||
raise e if only == :cask
|
raise e if only == :cask
|
||||||
end
|
end
|
||||||
@ -58,46 +70,30 @@ module Homebrew
|
|||||||
private :load_formula_or_cask
|
private :load_formula_or_cask
|
||||||
|
|
||||||
def resolve_formula(name)
|
def resolve_formula(name)
|
||||||
Formulary.resolve(name, spec: spec(nil), force_bottle: @force_bottle, flags: @flags)
|
Formulary.resolve(name, spec: spec, force_bottle: @force_bottle, flags: @flags)
|
||||||
end
|
end
|
||||||
private :resolve_formula
|
private :resolve_formula
|
||||||
|
|
||||||
def to_resolved_formulae
|
def to_resolved_formulae
|
||||||
@to_resolved_formulae ||= (downcased_unique_named - homebrew_tap_cask_names).map do |name|
|
@to_resolved_formulae ||= to_formulae_and_casks(only: :formula, method: :resolve)
|
||||||
resolve_formula(name)
|
.freeze
|
||||||
end.uniq(&:name).freeze
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_resolved_formulae_to_casks
|
def to_resolved_formulae_to_casks
|
||||||
@to_resolved_formulae_to_casks ||= begin
|
@to_resolved_formulae_to_casks ||= to_formulae_and_casks(method: :resolve)
|
||||||
resolved_formulae = []
|
.partition { |o| o.is_a?(Formula) }
|
||||||
casks = []
|
.map(&:freeze).freeze
|
||||||
|
|
||||||
downcased_unique_named.each do |name|
|
|
||||||
resolved_formulae << resolve_formula(name)
|
|
||||||
|
|
||||||
warn_if_cask_conflicts(name, "formula")
|
|
||||||
rescue FormulaUnavailableError
|
|
||||||
begin
|
|
||||||
casks << Cask::CaskLoader.load(name)
|
|
||||||
rescue Cask::CaskUnavailableError
|
|
||||||
raise "No available formula or cask with the name \"#{name}\""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
[resolved_formulae.freeze, casks.freeze].freeze
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert named arguments to `Tap`, `Formula` or `Cask` objects.
|
# Convert named arguments to `Tap`, `Formula` or `Cask` objects.
|
||||||
# If both a formula and cask exist with the same name, returns the
|
# If both a formula and cask exist with the same name, returns the
|
||||||
# formula and prints a warning unless `only` is specified.
|
# formula and prints a warning unless `only` is specified.
|
||||||
def to_objects(only: nil)
|
def to_objects(only: nil, method: nil)
|
||||||
@to_objects ||= {}
|
@to_objects ||= {}
|
||||||
@to_objects[only] ||= downcased_unique_named.flat_map do |name|
|
@to_objects[only] ||= downcased_unique_named.flat_map do |name|
|
||||||
next Tap.fetch(name) if only == :tap || (only.nil? && name.count("/") == 1 && !name.start_with?("./", "/"))
|
next Tap.fetch(name) if only == :tap || (only.nil? && name.count("/") == 1 && !name.start_with?("./", "/"))
|
||||||
|
|
||||||
load_formula_or_cask(name, only: only)
|
load_formula_or_cask(name, only: only, method: method)
|
||||||
end.uniq.freeze
|
end.uniq.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -132,12 +128,6 @@ module Homebrew
|
|||||||
end.uniq.freeze
|
end.uniq.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_casks
|
|
||||||
@to_casks ||= downcased_unique_named
|
|
||||||
.map { |name| Cask::CaskLoader.load(name, config: Cask::Config.from_args(@parent)) }
|
|
||||||
.freeze
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_kegs
|
def to_kegs
|
||||||
@to_kegs ||= downcased_unique_named.map do |name|
|
@to_kegs ||= downcased_unique_named.map do |name|
|
||||||
resolve_keg name
|
resolve_keg name
|
||||||
@ -187,9 +177,10 @@ module Homebrew
|
|||||||
end.uniq
|
end.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def spec(default = :stable)
|
def spec
|
||||||
@override_spec || default
|
@override_spec
|
||||||
end
|
end
|
||||||
|
private :spec
|
||||||
|
|
||||||
def resolve_keg(name)
|
def resolve_keg(name)
|
||||||
raise UsageError if name.blank?
|
raise UsageError if name.blank?
|
||||||
|
@ -16,6 +16,39 @@ module Homebrew
|
|||||||
module_function
|
module_function
|
||||||
|
|
||||||
def reinstall_args
|
def reinstall_args
|
||||||
|
cask_only_options = [
|
||||||
|
[:switch, "--cask", "--casks", {
|
||||||
|
description: "Treat all named arguments as casks.",
|
||||||
|
}],
|
||||||
|
*Cask::Cmd::OPTIONS,
|
||||||
|
*Cask::Cmd::AbstractCommand::OPTIONS,
|
||||||
|
]
|
||||||
|
|
||||||
|
formula_only_options = [
|
||||||
|
[:switch, "--formula", "--formulae", {
|
||||||
|
description: "Treat all named arguments as formulae.",
|
||||||
|
}],
|
||||||
|
[:switch, "-s", "--build-from-source", {
|
||||||
|
description: "Compile <formula> from source even if a bottle is available.",
|
||||||
|
}],
|
||||||
|
[:switch, "-i", "--interactive", {
|
||||||
|
description: "Download and patch <formula>, then open a shell. This allows the user to "\
|
||||||
|
"run `./configure --help` and otherwise determine how to turn the software "\
|
||||||
|
"package into a Homebrew package.",
|
||||||
|
}],
|
||||||
|
[:switch, "--force-bottle", {
|
||||||
|
description: "Install from a bottle if it exists for the current or newest version of "\
|
||||||
|
"macOS, even if it would not normally be used for installation.",
|
||||||
|
}],
|
||||||
|
[:switch, "--keep-tmp", {
|
||||||
|
description: "Retain the temporary files created during installation.",
|
||||||
|
}],
|
||||||
|
[:switch, "--display-times", {
|
||||||
|
env: :display_install_times,
|
||||||
|
description: "Print install times for each formula at the end of the run.",
|
||||||
|
}],
|
||||||
|
]
|
||||||
|
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
usage_banner <<~EOS
|
usage_banner <<~EOS
|
||||||
`reinstall` [<options>] <formula>|<cask>
|
`reinstall` [<options>] <formula>|<cask>
|
||||||
@ -29,26 +62,23 @@ module Homebrew
|
|||||||
switch "-d", "--debug",
|
switch "-d", "--debug",
|
||||||
description: "If brewing fails, open an interactive debugging session with access to IRB "\
|
description: "If brewing fails, open an interactive debugging session with access to IRB "\
|
||||||
"or a shell inside the temporary build directory."
|
"or a shell inside the temporary build directory."
|
||||||
switch "-s", "--build-from-source",
|
|
||||||
description: "Compile <formula> from source even if a bottle is available."
|
|
||||||
switch "-i", "--interactive",
|
|
||||||
description: "Download and patch <formula>, then open a shell. This allows the user to "\
|
|
||||||
"run `./configure --help` and otherwise determine how to turn the software "\
|
|
||||||
"package into a Homebrew package."
|
|
||||||
switch "--force-bottle",
|
|
||||||
description: "Install from a bottle if it exists for the current or newest version of "\
|
|
||||||
"macOS, even if it would not normally be used for installation."
|
|
||||||
switch "--keep-tmp",
|
|
||||||
description: "Retain the temporary files created during installation."
|
|
||||||
switch "-f", "--force",
|
switch "-f", "--force",
|
||||||
description: "Install without checking for previously installed keg-only or "\
|
description: "Install without checking for previously installed keg-only or "\
|
||||||
"non-migrated versions."
|
"non-migrated versions."
|
||||||
switch "-v", "--verbose",
|
switch "-v", "--verbose",
|
||||||
description: "Print the verification and postinstall steps."
|
description: "Print the verification and postinstall steps."
|
||||||
switch "--display-times",
|
|
||||||
env: :display_install_times,
|
|
||||||
description: "Print install times for each formula at the end of the run."
|
|
||||||
conflicts "--build-from-source", "--force-bottle"
|
conflicts "--build-from-source", "--force-bottle"
|
||||||
|
|
||||||
|
formula_only_options.each do |options|
|
||||||
|
send(*options)
|
||||||
|
conflicts "--cask", options[-2]
|
||||||
|
end
|
||||||
|
|
||||||
|
cask_only_options.each do |options|
|
||||||
|
send(*options)
|
||||||
|
conflicts "--formula", options[-2]
|
||||||
|
end
|
||||||
|
|
||||||
formula_options
|
formula_options
|
||||||
min_named 1
|
min_named 1
|
||||||
end
|
end
|
||||||
@ -61,8 +91,13 @@ module Homebrew
|
|||||||
|
|
||||||
Install.perform_preinstall_checks
|
Install.perform_preinstall_checks
|
||||||
|
|
||||||
resolved_formulae, casks = args.named.to_resolved_formulae_to_casks
|
only = :cask if args.cask? && !args.formula?
|
||||||
resolved_formulae.each do |f|
|
only = :formula if !args.cask? && args.formula?
|
||||||
|
|
||||||
|
formulae, casks = args.named.to_formulae_and_casks(only: only, method: :resolve)
|
||||||
|
.partition { |o| o.is_a?(Formula) }
|
||||||
|
|
||||||
|
formulae.each do |f|
|
||||||
if f.pinned?
|
if f.pinned?
|
||||||
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
|
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
|
||||||
next
|
next
|
||||||
@ -74,10 +109,7 @@ module Homebrew
|
|||||||
|
|
||||||
Upgrade.check_installed_dependents(args: args)
|
Upgrade.check_installed_dependents(args: args)
|
||||||
|
|
||||||
Homebrew.messages.display_messages(display_times: args.display_times?)
|
if casks.any?
|
||||||
|
|
||||||
return if casks.blank?
|
|
||||||
|
|
||||||
Cask::Cmd::Reinstall.reinstall_casks(
|
Cask::Cmd::Reinstall.reinstall_casks(
|
||||||
*casks,
|
*casks,
|
||||||
binaries: EnvConfig.cask_opts_binaries?,
|
binaries: EnvConfig.cask_opts_binaries?,
|
||||||
@ -88,4 +120,7 @@ module Homebrew
|
|||||||
quarantine: EnvConfig.cask_opts_quarantine?,
|
quarantine: EnvConfig.cask_opts_quarantine?,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user