diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 5ebd993613..f54633f9ea 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| option.long.first.present? && existing.second == option.long.first } @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 f87a2f81ec..29a7038e34 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 @@ -42,15 +40,7 @@ module Homebrew 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 + cmd_options = Commands.command_options(args.command) if args.compact? puts cmd_options.sort.map(&:first) * " " else @@ -64,20 +54,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 / (?