Merge pull request #5251 from GauthamGoli/outdated-args
outdated: Use CLI::Parser to parse args
This commit is contained in:
commit
b04fa04306
@ -19,17 +19,45 @@
|
|||||||
|
|
||||||
require "formula"
|
require "formula"
|
||||||
require "keg"
|
require "keg"
|
||||||
|
require "cli_parser"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
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
|
def outdated
|
||||||
|
outdated_args.parse
|
||||||
|
|
||||||
formulae = if ARGV.resolved_formulae.empty?
|
formulae = if ARGV.resolved_formulae.empty?
|
||||||
Formula.installed
|
Formula.installed
|
||||||
else
|
else
|
||||||
ARGV.resolved_formulae
|
ARGV.resolved_formulae
|
||||||
end
|
end
|
||||||
if ARGV.json == "v1"
|
if args.json == "v1"
|
||||||
outdated = print_outdated_json(formulae)
|
outdated = print_outdated_json(formulae)
|
||||||
else
|
else
|
||||||
outdated = print_outdated(formulae)
|
outdated = print_outdated(formulae)
|
||||||
@ -38,8 +66,8 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def print_outdated(formulae)
|
def print_outdated(formulae)
|
||||||
verbose = ($stdout.tty? || ARGV.verbose?) && !ARGV.flag?("--quiet")
|
verbose = ($stdout.tty? || args.verbose?) && !args.quiet?
|
||||||
fetch_head = ARGV.fetch_head?
|
fetch_head = args.fetch_HEAD?
|
||||||
|
|
||||||
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
||||||
.sort
|
.sort
|
||||||
@ -76,7 +104,7 @@ module Homebrew
|
|||||||
|
|
||||||
def print_outdated_json(formulae)
|
def print_outdated_json(formulae)
|
||||||
json = []
|
json = []
|
||||||
fetch_head = ARGV.fetch_head?
|
fetch_head = args.fetch_HEAD?
|
||||||
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
||||||
|
|
||||||
outdated = outdated_formulae.each do |f|
|
outdated = outdated_formulae.each do |f|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user