Skip to content

Commit

Permalink
Merge pull request #17030 from Homebrew/strict-parser
Browse files Browse the repository at this point in the history
Enable strict typing in `CLI::Parser`
  • Loading branch information
dduugg committed Apr 21, 2024
2 parents eead9dd + 1172013 commit cfa3f92
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 78 deletions.
3 changes: 3 additions & 0 deletions Library/Homebrew/abstract_command.rb
Expand Up @@ -26,6 +26,9 @@ def command_name = Utils.underscore(T.must(name).split("::").fetch(-1)).tr("_",
sig { params(name: String).returns(T.nilable(T.class_of(AbstractCommand))) }
def command(name) = subclasses.find { _1.command_name == name }

sig { returns(T::Boolean) }
def dev_cmd? = T.must(name).start_with?("Homebrew::DevCmd")

sig { returns(CLI::Parser) }
def parser = CLI::Parser.new(self, &@parser_block)

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/brew.rb
Expand Up @@ -136,17 +136,17 @@
end
rescue UsageError => e
require "help"
Homebrew::Help.help cmd, remaining_args: args.remaining, usage_error: e.message
Homebrew::Help.help cmd, remaining_args: args&.remaining, usage_error: e.message
rescue SystemExit => e
onoe "Kernel.exit" if args.debug? && !e.success?
onoe "Kernel.exit" if args&.debug? && !e.success?
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug")
raise
rescue Interrupt
$stderr.puts # seemingly a newline is typical
exit 130
rescue BuildError => e
Utils::Analytics.report_build_error(e)
e.dump(verbose: args&.verbose?)
e.dump(verbose: args&.verbose? || false)

if OS.unsupported_configuration?
$stderr.puts "#{Tty.bold}Do not report this issue: you are running in an unsupported configuration.#{Tty.reset}"
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/cli/args.rbi
Expand Up @@ -14,6 +14,9 @@ class Homebrew::CLI::Args
sig { returns(T::Boolean) }
def quiet?; end

sig { returns(T::Array[String]) }
def remaining; end

sig { returns(T::Boolean) }
def verbose?; end
end

0 comments on commit cfa3f92

Please sign in to comment.