Merge pull request #13706 from hyuraku/add-dry-run-option-to-brew-install
Add `--dry-run` option to `cmd#install`
This commit is contained in:
commit
9fa87ccbfc
@ -56,7 +56,8 @@ module Cask
|
|||||||
require_sha: nil,
|
require_sha: nil,
|
||||||
quarantine: nil,
|
quarantine: nil,
|
||||||
quiet: nil,
|
quiet: nil,
|
||||||
zap: nil
|
zap: nil,
|
||||||
|
dry_run: nil
|
||||||
)
|
)
|
||||||
odie "Installing casks is supported only on macOS" unless OS.mac?
|
odie "Installing casks is supported only on macOS" unless OS.mac?
|
||||||
|
|
||||||
@ -73,6 +74,27 @@ module Cask
|
|||||||
|
|
||||||
options[:quarantine] = true if options[:quarantine].nil?
|
options[:quarantine] = true if options[:quarantine].nil?
|
||||||
|
|
||||||
|
if dry_run
|
||||||
|
if (casks_to_install = casks.reject(&:installed?).presence)
|
||||||
|
plural = "cask".pluralize(casks_to_install.count)
|
||||||
|
ohai "Would install #{casks_to_install.count} #{plural}:"
|
||||||
|
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?
|
||||||
|
|
||||||
|
plural = "dependency".pluralize(dep_names.count)
|
||||||
|
ohai "Would install #{dep_names.count} #{plural} for #{cask.full_name}:"
|
||||||
|
puts dep_names.join(" ")
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
require "cask/installer"
|
require "cask/installer"
|
||||||
|
|
||||||
casks.each do |cask|
|
casks.each do |cask|
|
||||||
|
|||||||
@ -45,6 +45,8 @@ module Homebrew
|
|||||||
"(binaries and symlinks are excluded, unless originally from the same cask)."
|
"(binaries and symlinks are excluded, unless originally from the same cask)."
|
||||||
switch "-v", "--verbose",
|
switch "-v", "--verbose",
|
||||||
description: "Print the verification and postinstall steps."
|
description: "Print the verification and postinstall steps."
|
||||||
|
switch "-n", "--dry-run",
|
||||||
|
description: "Show what would be installed, but do not actually install anything."
|
||||||
[
|
[
|
||||||
[:switch, "--formula", "--formulae", {
|
[:switch, "--formula", "--formulae", {
|
||||||
description: "Treat all named arguments as formulae.",
|
description: "Treat all named arguments as formulae.",
|
||||||
@ -193,6 +195,7 @@ module Homebrew
|
|||||||
skip_cask_deps: args.skip_cask_deps?,
|
skip_cask_deps: args.skip_cask_deps?,
|
||||||
quarantine: args.quarantine?,
|
quarantine: args.quarantine?,
|
||||||
quiet: args.quiet?,
|
quiet: args.quiet?,
|
||||||
|
dry_run: args.dry_run?,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -242,6 +245,7 @@ module Homebrew
|
|||||||
debug: args.debug?,
|
debug: args.debug?,
|
||||||
quiet: args.quiet?,
|
quiet: args.quiet?,
|
||||||
verbose: args.verbose?,
|
verbose: args.verbose?,
|
||||||
|
dry_run: args.dry_run?,
|
||||||
)
|
)
|
||||||
|
|
||||||
Upgrade.check_installed_dependents(
|
Upgrade.check_installed_dependents(
|
||||||
@ -257,9 +261,10 @@ module Homebrew
|
|||||||
debug: args.debug?,
|
debug: args.debug?,
|
||||||
quiet: args.quiet?,
|
quiet: args.quiet?,
|
||||||
verbose: args.verbose?,
|
verbose: args.verbose?,
|
||||||
|
dry_run: args.dry_run?,
|
||||||
)
|
)
|
||||||
|
|
||||||
Cleanup.periodic_clean!
|
Cleanup.periodic_clean!(dry_run: args.dry_run?)
|
||||||
|
|
||||||
Homebrew.messages.display_messages(display_times: args.display_times?)
|
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||||
rescue FormulaUnreadableError, FormulaClassUnavailableError,
|
rescue FormulaUnreadableError, FormulaClassUnavailableError,
|
||||||
|
|||||||
@ -278,10 +278,11 @@ module Homebrew
|
|||||||
overwrite: false,
|
overwrite: false,
|
||||||
debug: false,
|
debug: false,
|
||||||
quiet: false,
|
quiet: false,
|
||||||
verbose: false
|
verbose: false,
|
||||||
|
dry_run: false
|
||||||
)
|
)
|
||||||
formula_installers = formulae_to_install.map do |f|
|
formula_installers = formulae_to_install.map do |f|
|
||||||
Migrator.migrate_if_needed(f, force: force)
|
Migrator.migrate_if_needed(f, force: force, dry_run: dry_run)
|
||||||
build_options = f.build
|
build_options = f.build
|
||||||
|
|
||||||
fi = FormulaInstaller.new(
|
fi = FormulaInstaller.new(
|
||||||
@ -307,8 +308,10 @@ module Homebrew
|
|||||||
)
|
)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
unless dry_run
|
||||||
fi.prelude
|
fi.prelude
|
||||||
fi.fetch
|
fi.fetch
|
||||||
|
end
|
||||||
fi
|
fi
|
||||||
rescue CannotInstallFormulaError => e
|
rescue CannotInstallFormulaError => e
|
||||||
ofail e.message
|
ofail e.message
|
||||||
@ -319,6 +322,20 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end.compact
|
end.compact
|
||||||
|
|
||||||
|
if dry_run
|
||||||
|
if (formulae_name_to_install = formulae_to_install.map(&:name))
|
||||||
|
plural = "formula".pluralize(formulae_name_to_install.count)
|
||||||
|
ohai "Would install #{formulae_name_to_install.count} #{plural}:"
|
||||||
|
puts formulae_name_to_install.join(" ")
|
||||||
|
|
||||||
|
formula_installers.each do |fi|
|
||||||
|
f = fi.formula
|
||||||
|
print_dry_run_dependencies(f, fi.compute_dependencies, &:name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
formula_installers.each do |fi|
|
formula_installers.each do |fi|
|
||||||
install_formula(fi)
|
install_formula(fi)
|
||||||
Cleanup.install_formula_clean!(fi.formula)
|
Cleanup.install_formula_clean!(fi.formula)
|
||||||
@ -333,6 +350,15 @@ module Homebrew
|
|||||||
Upgrade.install_formula(formula_installer, upgrade: upgrade)
|
Upgrade.install_formula(formula_installer, upgrade: upgrade)
|
||||||
end
|
end
|
||||||
private_class_method :install_formula
|
private_class_method :install_formula
|
||||||
|
|
||||||
|
def print_dry_run_dependencies(formula, dependencies, &block)
|
||||||
|
return if dependencies.empty?
|
||||||
|
|
||||||
|
plural = "dependency".pluralize(dependencies.count)
|
||||||
|
ohai "Would install #{dependencies.count} #{plural} for #{formula.name}:"
|
||||||
|
formula_names = dependencies.map(&:first).map(&:to_formula).map(&block)
|
||||||
|
puts formula_names.join(" ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -94,22 +94,6 @@ module Homebrew
|
|||||||
.map { |k| Keg.new(k.resolved_path) }
|
.map { |k| Keg.new(k.resolved_path) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_dry_run_dependencies(formula, fi_deps)
|
|
||||||
return if fi_deps.empty?
|
|
||||||
|
|
||||||
plural = "dependency".pluralize(fi_deps.count)
|
|
||||||
ohai "Would upgrade #{fi_deps.count} #{plural} for #{formula.full_specified_name}:"
|
|
||||||
formulae_upgrades = fi_deps.map(&:first).map(&:to_formula).map do |f|
|
|
||||||
name = f.full_specified_name
|
|
||||||
if f.optlinked?
|
|
||||||
"#{name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
|
|
||||||
else
|
|
||||||
"#{name} #{f.pkg_version}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
puts formulae_upgrades.join(", ")
|
|
||||||
end
|
|
||||||
|
|
||||||
def print_upgrade_message(formula, fi_options)
|
def print_upgrade_message(formula, fi_options)
|
||||||
version_upgrade = if formula.optlinked?
|
version_upgrade = if formula.optlinked?
|
||||||
"#{Keg.new(formula.opt_prefix).version} -> #{formula.pkg_version}"
|
"#{Keg.new(formula.opt_prefix).version} -> #{formula.pkg_version}"
|
||||||
@ -178,7 +162,14 @@ module Homebrew
|
|||||||
formula = formula_installer.formula
|
formula = formula_installer.formula
|
||||||
|
|
||||||
if dry_run
|
if dry_run
|
||||||
print_dry_run_dependencies(formula, formula_installer.compute_dependencies)
|
Install.print_dry_run_dependencies(formula, formula_installer.compute_dependencies) do |f|
|
||||||
|
name = f.full_specified_name
|
||||||
|
if f.optlinked?
|
||||||
|
"#{name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
|
||||||
|
else
|
||||||
|
"#{name} #{f.pkg_version}"
|
||||||
|
end
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user