2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "formula"
|
2015-12-27 19:12:27 +01:00
|
|
|
require "options"
|
2011-03-19 09:58:42 -07:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(CLI::Parser) }
|
2018-11-07 21:59:04 +05:30
|
|
|
def options_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2021-01-15 13:04:00 +01:00
|
|
|
`options` [<options>] [<formula>] [<formula> ...]
|
2018-11-07 21:59:04 +05:30
|
|
|
|
2019-08-20 00:04:14 -04:00
|
|
|
Show install options specific to <formula>.
|
2018-11-07 21:59:04 +05:30
|
|
|
EOS
|
|
|
|
switch "--compact",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Show all options on a single line separated by spaces."
|
2018-11-07 21:59:04 +05:30
|
|
|
switch "--installed",
|
2019-08-20 00:04:14 -04:00
|
|
|
description: "Show options for formulae that are currently installed."
|
2019-08-09 14:23:04 -04:00
|
|
|
switch "--all",
|
|
|
|
description: "Show options for all available formulae."
|
2020-06-26 18:10:16 -04:00
|
|
|
flag "--command=",
|
|
|
|
description: "Show options for the specified <command>."
|
2020-07-30 18:40:10 +02:00
|
|
|
|
2020-06-26 18:10:16 -04:00
|
|
|
conflicts "--installed", "--all", "--command"
|
2021-01-10 14:26:40 -05:00
|
|
|
|
|
|
|
named_args :formula
|
2018-11-07 21:59:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-26 15:08:45 -05:00
|
|
|
def options
|
2020-07-30 18:40:10 +02:00
|
|
|
args = options_args.parse
|
2018-11-07 21:59:04 +05:30
|
|
|
|
|
|
|
if args.all?
|
2020-07-31 19:24:13 +02:00
|
|
|
puts_options Formula.to_a.sort, args: args
|
2018-11-07 21:59:04 +05:30
|
|
|
elsif args.installed?
|
2020-07-31 19:24:13 +02:00
|
|
|
puts_options Formula.installed.sort, args: args
|
2021-01-15 00:13:10 -05:00
|
|
|
elsif args.command.present?
|
2021-01-05 22:44:39 -05:00
|
|
|
cmd_options = Commands.command_options(args.command)
|
2021-01-15 00:13:10 -05:00
|
|
|
odie "Unknown command: #{args.command}" if cmd_options.nil?
|
|
|
|
|
2020-06-26 18:10:16 -04:00
|
|
|
if args.compact?
|
|
|
|
puts cmd_options.sort.map(&:first) * " "
|
|
|
|
else
|
|
|
|
cmd_options.sort.each { |option, desc| puts "#{option}\n\t#{desc}" }
|
|
|
|
puts
|
|
|
|
end
|
2020-03-04 17:28:15 +00:00
|
|
|
elsif args.no_named?
|
|
|
|
raise FormulaUnspecifiedError
|
2013-06-26 15:08:45 -05:00
|
|
|
else
|
2020-08-19 10:34:48 -04:00
|
|
|
puts_options args.named.to_formulae, args: args
|
2011-11-22 19:28:05 -06:00
|
|
|
end
|
2011-03-19 09:58:42 -07:00
|
|
|
end
|
|
|
|
|
2020-07-31 19:24:13 +02:00
|
|
|
def puts_options(formulae, args:)
|
2013-06-26 15:08:45 -05:00
|
|
|
formulae.each do |f|
|
2014-08-10 21:45:24 -05:00
|
|
|
next if f.options.empty?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2018-11-07 21:59:04 +05:30
|
|
|
if args.compact?
|
2014-08-10 21:45:24 -05:00
|
|
|
puts f.options.as_flags.sort * " "
|
2011-03-10 21:32:10 -08:00
|
|
|
else
|
2015-05-27 21:08:24 +08:00
|
|
|
puts f.full_name if formulae.length > 1
|
2020-08-17 19:53:37 +02:00
|
|
|
Options.dump_for_formula f
|
2011-03-10 21:32:10 -08:00
|
|
|
puts
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-04 15:40:36 -04:00
|
|
|
end
|