cmd/upgrade: Use CLI::Parser to parse args
This commit is contained in:
parent
3bdc4c294d
commit
22c2b06fa5
@ -23,10 +23,37 @@ require "formula_installer"
|
||||
require "development_tools"
|
||||
require "messages"
|
||||
require "cleanup"
|
||||
require "cli_parser"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
def upgrade_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
usage_banner <<~EOS
|
||||
`upgrade` [<install-options>] [<options>] [<formulae>]
|
||||
|
||||
Upgrade outdated, unpinned brews (with existing install options).
|
||||
Options for the `install` command are also valid here.
|
||||
|
||||
If <formulae> are given, upgrade only the specified brews (unless they
|
||||
are pinned; see `pin`, `unpin`).
|
||||
EOS
|
||||
switch "--fetch-HEAD",
|
||||
description: "Fetch the upstream repository to detect if the HEAD installation of the "\
|
||||
"formula is outdated. Otherwise, the repository's HEAD will be checked for "\
|
||||
"updates when a new stable or devel version has been released."
|
||||
switch "--ignore-pinned",
|
||||
description: "Set a 0 exit code even if pinned formulae are not upgraded."
|
||||
switch "--build-bottle",
|
||||
description: "Prepare the formula for eventual bottling during installation."
|
||||
switch "--display-times",
|
||||
description: "Print install times for each formula at the end of the run."
|
||||
switch :verbose
|
||||
switch :debug
|
||||
end
|
||||
end
|
||||
|
||||
def upgrade
|
||||
if ARGV.include?("--cleanup")
|
||||
odisabled("'brew upgrade --cleanup'")
|
||||
@ -40,13 +67,13 @@ module Homebrew
|
||||
|
||||
if ARGV.named.empty?
|
||||
outdated = Formula.installed.select do |f|
|
||||
f.outdated?(fetch_head: ARGV.fetch_head?)
|
||||
f.outdated?(fetch_head: args.fetch_HEAD?)
|
||||
end
|
||||
|
||||
exit 0 if outdated.empty?
|
||||
else
|
||||
outdated = ARGV.resolved_formulae.select do |f|
|
||||
f.outdated?(fetch_head: ARGV.fetch_head?)
|
||||
f.outdated?(fetch_head: args.fetch_HEAD?)
|
||||
end
|
||||
|
||||
(ARGV.resolved_formulae - outdated).each do |f|
|
||||
@ -65,7 +92,7 @@ module Homebrew
|
||||
outdated -= pinned
|
||||
formulae_to_install = outdated.map(&:latest_formula)
|
||||
|
||||
if !pinned.empty? && !ARGV.include?("--ignore-pinned")
|
||||
if !pinned.empty? && !args.ignore_pinned?
|
||||
ofail "Not upgrading #{pinned.count} pinned #{"package".pluralize(pinned.count)}:"
|
||||
puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", "
|
||||
end
|
||||
@ -144,7 +171,7 @@ module Homebrew
|
||||
|
||||
fi = FormulaInstaller.new(f)
|
||||
fi.options = options
|
||||
fi.build_bottle = ARGV.build_bottle? || (!f.bottle_defined? && f.build.bottle?)
|
||||
fi.build_bottle = args.build_bottle? || (!f.bottle_defined? && f.build.bottle?)
|
||||
fi.installed_on_request = !ARGV.named.empty?
|
||||
fi.link_keg ||= keg_was_linked if keg_had_linked_opt
|
||||
if tab
|
||||
@ -203,7 +230,7 @@ module Homebrew
|
||||
next if formulae_to_upgrade.include?(f)
|
||||
next if formulae_pinned.include?(f)
|
||||
|
||||
if f.outdated?(fetch_head: ARGV.fetch_head?)
|
||||
if f.outdated?(fetch_head: args.fetch_HEAD?)
|
||||
if f.pinned?
|
||||
formulae_pinned << f
|
||||
else
|
||||
@ -247,7 +274,7 @@ module Homebrew
|
||||
checker = LinkageChecker.new(keg, cache_db: db)
|
||||
|
||||
if checker.broken_library_linkage?
|
||||
if f.outdated?(fetch_head: ARGV.fetch_head?)
|
||||
if f.outdated?(fetch_head: args.fetch_HEAD?)
|
||||
# Outdated formulae = pinned formulae (see function above)
|
||||
formulae_pinned_and_outdated << f
|
||||
else
|
||||
@ -295,7 +322,7 @@ module Homebrew
|
||||
|
||||
return if kegs.empty?
|
||||
|
||||
oh1 "Checking dependents for outdated formulae" if ARGV.verbose?
|
||||
oh1 "Checking dependents for outdated formulae" if args.verbose?
|
||||
upgradable, pinned = upgradable_dependents(kegs, formulae).map(&:to_a)
|
||||
|
||||
upgradable.sort! { |a, b| depends_on(a, b) }
|
||||
@ -310,7 +337,7 @@ module Homebrew
|
||||
|
||||
# Print the upgradable dependents.
|
||||
if upgradable.empty?
|
||||
ohai "No dependents to upgrade" if ARGV.verbose?
|
||||
ohai "No dependents to upgrade" if args.verbose?
|
||||
else
|
||||
ohai "Upgrading #{upgradable.count} #{"dependent".pluralize(upgradable.count)}:"
|
||||
formulae_upgrades = upgradable.map do |f|
|
||||
@ -328,7 +355,7 @@ module Homebrew
|
||||
# Assess the dependents tree again.
|
||||
kegs = formulae_with_runtime_dependencies
|
||||
|
||||
oh1 "Checking dependents for broken library links" if ARGV.verbose?
|
||||
oh1 "Checking dependents for broken library links" if args.verbose?
|
||||
reinstallable, pinned = broken_dependents(kegs, formulae).map(&:to_a)
|
||||
|
||||
reinstallable.sort! { |a, b| depends_on(a, b) }
|
||||
@ -343,7 +370,7 @@ module Homebrew
|
||||
|
||||
# Print the broken dependents.
|
||||
if reinstallable.empty?
|
||||
ohai "No broken dependents to reinstall" if ARGV.verbose?
|
||||
ohai "No broken dependents to reinstall" if args.verbose?
|
||||
else
|
||||
ohai "Reinstalling #{reinstallable.count} broken #{"dependent".pluralize(reinstallable.count)} from source:"
|
||||
puts reinstallable.map(&:full_specified_name).join(", ")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user