brew/Library/Homebrew/cmd/options.rb

73 lines
2.0 KiB
Ruby
Raw Normal View History

2023-03-06 09:49:53 -08:00
# typed: true
# frozen_string_literal: true
2024-04-01 09:10:51 -07:00
require "abstract_command"
require "formula"
require "options"
2011-03-19 09:58:42 -07:00
module Homebrew
2024-04-01 09:10:51 -07:00
module Cmd
class OptionsCmd < AbstractCommand
cmd_args do
description <<~EOS
Show install options specific to <formula>.
EOS
switch "--compact",
description: "Show all options on a single line separated by spaces."
switch "--installed",
description: "Show options for formulae that are currently installed."
switch "--eval-all",
description: "Evaluate all available formulae and casks, whether installed or not, to show their " \
"options."
flag "--command=",
description: "Show options for the specified <command>."
2016-09-26 01:44:51 +02:00
2024-04-01 09:10:51 -07:00
conflicts "--installed", "--all", "--command"
2020-07-30 18:40:10 +02:00
2024-04-01 09:10:51 -07:00
named_args :formula
end
2018-11-07 21:59:04 +05:30
2024-04-01 09:10:51 -07:00
sig { override.void }
def run
all = args.eval_all?
2024-04-01 09:10:51 -07:00
if all
puts_options(Formula.all(eval_all: args.eval_all?).sort)
elsif args.installed?
puts_options(Formula.installed.sort)
elsif args.command.present?
cmd_options = Commands.command_options(T.must(args.command))
odie "Unknown command: brew #{args.command}" if cmd_options.nil?
2024-04-01 09:10:51 -07:00
if args.compact?
puts cmd_options.sort.map(&:first) * " "
else
cmd_options.sort.each { |option, desc| puts "#{option}\n\t#{desc}" }
puts
end
elsif args.no_named?
raise FormulaUnspecifiedError
else
puts_options args.named.to_formulae
end
end
2011-03-19 09:58:42 -07:00
2024-04-01 09:10:51 -07:00
private
def puts_options(formulae)
formulae.each do |f|
next if f.options.empty?
2018-09-17 02:45:00 +02:00
2024-04-01 09:10:51 -07:00
if args.compact?
puts f.options.as_flags.sort * " "
else
puts f.full_name if formulae.length > 1
Options.dump_for_formula f
puts
end
end
2011-03-10 21:32:10 -08:00
end
end
end
end