Merge pull request #5273 from GauthamGoli/options-args
options: Use CLI::Parser to parse args
This commit is contained in:
commit
0722d816ac
@ -10,17 +10,37 @@
|
|||||||
|
|
||||||
require "formula"
|
require "formula"
|
||||||
require "options"
|
require "options"
|
||||||
|
require "cli_parser"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
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
|
def options
|
||||||
if ARGV.include? "--all"
|
options_args.parse
|
||||||
|
|
||||||
|
if args.all?
|
||||||
puts_options Formula.to_a.sort
|
puts_options Formula.to_a.sort
|
||||||
elsif ARGV.include? "--installed"
|
elsif args.installed?
|
||||||
puts_options Formula.installed.sort
|
puts_options Formula.installed.sort
|
||||||
else
|
else
|
||||||
raise FormulaUnspecifiedError if ARGV.named.empty?
|
raise FormulaUnspecifiedError if args.remaining.empty?
|
||||||
|
|
||||||
puts_options ARGV.formulae
|
puts_options ARGV.formulae
|
||||||
end
|
end
|
||||||
@ -30,7 +50,7 @@ module Homebrew
|
|||||||
formulae.each do |f|
|
formulae.each do |f|
|
||||||
next if f.options.empty?
|
next if f.options.empty?
|
||||||
|
|
||||||
if ARGV.include? "--compact"
|
if args.compact?
|
||||||
puts f.options.as_flags.sort * " "
|
puts f.options.as_flags.sort * " "
|
||||||
else
|
else
|
||||||
puts f.full_name if formulae.length > 1
|
puts f.full_name if formulae.length > 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user