Skip to content

Commit

Permalink
Enable strict typing in CLI::Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Apr 4, 2024
1 parent a2c59c0 commit 46549dd
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 80 deletions.
3 changes: 3 additions & 0 deletions Library/Homebrew/abstract_command.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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: T.must(args).remaining, usage_error: e.message
rescue SystemExit => e
onoe "Kernel.exit" if args.debug? && !e.success?
onoe "Kernel.exit" if T.must(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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 46549dd

Please sign in to comment.