diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index f54633f9ea..75ff6ed78c 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -539,7 +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.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 29a7038e34..ba6616c400 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -39,8 +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? + 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 diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index 62a5e84e57..1f7676178a 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -197,7 +197,7 @@ module Commands HOMEBREW_CACHE.mkpath cmds = commands(aliases: true).reject do |cmd| - # TODO: remove the cask check when `brew cask` is removed + # TODO: (2.8) remove the cask check when `brew cask` is removed cmd.start_with?("cask ") || Homebrew::Completions::COMPLETIONS_EXCLUSION_LIST.include?(cmd) end @@ -206,8 +206,8 @@ module Commands end def command_options(command) - path = Commands.path(command) - return unless path + path = self.path(command) + return if path.blank? if cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path) cmd_parser.processed_options.map do |short, long, _, desc| @@ -229,8 +229,8 @@ module Commands end def named_args_type(command) - path = Commands.path(command) - return unless path + path = self.path(command) + return if path.blank? cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path) return if cmd_parser.blank?