options: Use CLI::Parser to parse args

This commit is contained in:
Gautham Goli 2018-11-07 21:59:04 +05:30
parent fd8206567b
commit 5fbbe888f1
No known key found for this signature in database
GPG Key ID: 6A9ABBC284468364

View File

@ -10,17 +10,37 @@
require "formula"
require "options"
require "cli_parser"
module Homebrew
module_function
def options_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`options` [<options>] <formulae>
Display install options specific to <formulae>
EOS
switch "--compact",
description: "Show all options on a single line separated by spaces."
switch "--all",
description: "Show options for all formulae."
switch "--installed",
description: "Show options for all installed formulae."
switch :debug
end
end
def options
if ARGV.include? "--all"
options_args.parse
if args.all?
puts_options Formula.to_a.sort
elsif ARGV.include? "--installed"
elsif args.installed?
puts_options Formula.installed.sort
else
raise FormulaUnspecifiedError if ARGV.named.empty?
raise FormulaUnspecifiedError if args.remaining.empty?
puts_options ARGV.formulae
end
@ -30,7 +50,7 @@ module Homebrew
formulae.each do |f|
next if f.options.empty?
if ARGV.include? "--compact"
if args.compact?
puts f.options.as_flags.sort * " "
else
puts f.full_name if formulae.length > 1