From 22c2b06fa583f3ebaf33f6cbb7055e6b1dbc2cd0 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Tue, 29 Jan 2019 19:52:06 +0530 Subject: [PATCH] cmd/upgrade: Use CLI::Parser to parse args --- Library/Homebrew/cmd/upgrade.rb | 47 ++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 7a9fad981c..68ab9f7c81 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -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` [] [] [] + + Upgrade outdated, unpinned brews (with existing install options). + Options for the `install` command are also valid here. + + If 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(", ")