Incorporate suggestions from code review

Co-Authored-By: Seeker <meaningseeking@protonmail.com>
This commit is contained in:
Rylan Polster 2021-01-15 00:13:10 -05:00
parent 3af16832d9
commit eebc161ea5
3 changed files with 9 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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?