Merge pull request #5251 from GauthamGoli/outdated-args

outdated: Use CLI::Parser to parse args
This commit is contained in:
Gautham Goli 2018-11-05 21:54:52 +05:30 committed by GitHub
commit b04fa04306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,17 +19,45 @@
require "formula"
require "keg"
require "cli_parser"
module Homebrew
module_function
def outdated_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`outdated` [<options>]
Show formulae that have an updated version available.
By default, version information is displayed in interactive shells, and
suppressed otherwise.
EOS
switch :quiet,
description: "List only the names of outdated brews (takes precedence over `--verbose`)."
switch :verbose,
description: "Display detailed version information."
flag "--json=",
description: "Show output in JSON format for provided <version>. Currently the only "\
"accepted value of <version> is `v1`."
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 :debug
end
end
def outdated
outdated_args.parse
formulae = if ARGV.resolved_formulae.empty?
Formula.installed
else
ARGV.resolved_formulae
end
if ARGV.json == "v1"
if args.json == "v1"
outdated = print_outdated_json(formulae)
else
outdated = print_outdated(formulae)
@ -38,8 +66,8 @@ module Homebrew
end
def print_outdated(formulae)
verbose = ($stdout.tty? || ARGV.verbose?) && !ARGV.flag?("--quiet")
fetch_head = ARGV.fetch_head?
verbose = ($stdout.tty? || args.verbose?) && !args.quiet?
fetch_head = args.fetch_HEAD?
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
.sort
@ -76,7 +104,7 @@ module Homebrew
def print_outdated_json(formulae)
json = []
fetch_head = ARGV.fetch_head?
fetch_head = args.fetch_HEAD?
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
outdated = outdated_formulae.each do |f|