Port Homebrew::Cmd::Options
This commit is contained in:
parent
c5dfac1f2c
commit
57442ab67e
@ -1,15 +1,14 @@
|
|||||||
# typed: true
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "formula"
|
require "formula"
|
||||||
require "options"
|
require "options"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module Cmd
|
||||||
|
class OptionsCmd < AbstractCommand
|
||||||
sig { returns(CLI::Parser) }
|
cmd_args do
|
||||||
def options_args
|
|
||||||
Homebrew::CLI::Parser.new do
|
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Show install options specific to <formula>.
|
Show install options specific to <formula>.
|
||||||
EOS
|
EOS
|
||||||
@ -27,19 +26,17 @@ module Homebrew
|
|||||||
|
|
||||||
named_args :formula
|
named_args :formula
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def options
|
|
||||||
args = options_args.parse
|
|
||||||
|
|
||||||
|
sig { override.void }
|
||||||
|
def run
|
||||||
all = args.eval_all?
|
all = args.eval_all?
|
||||||
|
|
||||||
if all
|
if all
|
||||||
puts_options(Formula.all(eval_all: args.eval_all?).sort, args:)
|
puts_options(Formula.all(eval_all: args.eval_all?).sort)
|
||||||
elsif args.installed?
|
elsif args.installed?
|
||||||
puts_options(Formula.installed.sort, args:)
|
puts_options(Formula.installed.sort)
|
||||||
elsif args.command.present?
|
elsif args.command.present?
|
||||||
cmd_options = Commands.command_options(args.command)
|
cmd_options = Commands.command_options(T.must(args.command))
|
||||||
odie "Unknown command: #{args.command}" if cmd_options.nil?
|
odie "Unknown command: #{args.command}" if cmd_options.nil?
|
||||||
|
|
||||||
if args.compact?
|
if args.compact?
|
||||||
@ -51,11 +48,13 @@ module Homebrew
|
|||||||
elsif args.no_named?
|
elsif args.no_named?
|
||||||
raise FormulaUnspecifiedError
|
raise FormulaUnspecifiedError
|
||||||
else
|
else
|
||||||
puts_options args.named.to_formulae, args:
|
puts_options args.named.to_formulae
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def puts_options(formulae, args:)
|
private
|
||||||
|
|
||||||
|
def puts_options(formulae)
|
||||||
formulae.each do |f|
|
formulae.each do |f|
|
||||||
next if f.options.empty?
|
next if f.options.empty?
|
||||||
|
|
||||||
@ -69,3 +68,5 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cmd/options"
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
|
||||||
RSpec.describe "brew options" do
|
RSpec.describe Homebrew::Cmd::OptionsCmd do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
|
|
||||||
it "prints a given Formula's options", :integration_test do
|
it "prints a given Formula's options", :integration_test do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user