diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 5ebd993613..75ff6ed78c 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -16,7 +16,7 @@ module Homebrew class Parser extend T::Sig - attr_reader :processed_options, :hide_from_man_page + attr_reader :processed_options, :hide_from_man_page, :named_args_type def self.from_cmd_path(cmd_path) cmd_args_method_name = Commands.args_method_name(cmd_path) @@ -539,6 +539,7 @@ module Homebrew def process_option(*args) option, = @parser.make_switch(args) + @processed_options.reject! { |existing| existing.second == option.long.first } if option.long.first.present? @processed_options << [option.short.first, option.long.first, option.arg, option.desc.first] end diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index bf7238d47e..93481dedec 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -3,8 +3,6 @@ require "formula" require "options" -require "cli/parser" -require "commands" module Homebrew extend T::Sig @@ -41,16 +39,10 @@ module Homebrew puts_options Formula.to_a.sort, args: args elsif args.installed? puts_options Formula.installed.sort, args: args - elsif !args.command.nil? - path = Commands.path(args.command) - odie "Unknown command: #{args.command}" unless path - cmd_options = if cmd_parser = CLI::Parser.from_cmd_path(path) - cmd_parser.processed_options.map do |short, long, _, desc| - [long || short, desc] - end - else - cmd_comment_options(path) - end + elsif args.command.present? + cmd_options = Commands.command_options(args.command) + odie "Unknown command: #{args.command}" if cmd_options.nil? + if args.compact? puts cmd_options.sort.map(&:first) * " " else @@ -64,20 +56,6 @@ module Homebrew end end - def cmd_comment_options(cmd_path) - options = [] - comment_lines = cmd_path.read.lines.grep(/^#:/) - return options if comment_lines.empty? - - # skip the comment's initial usage summary lines - comment_lines.slice(2..-1).each do |line| - if / (?