Skip to content

Commit 9fd2b27

Browse files
authored
Merge pull request #19151 from Homebrew/fix_case_commands
Fix handling of case-mistyped commands
2 parents 3060224 + d555ec9 commit 9fd2b27

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Library/Homebrew/brew.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
ENV["PATH"] = path.to_s
6262

6363
require "commands"
64+
require "warnings"
6465

6566
internal_cmd = Commands.valid_internal_cmd?(cmd) || Commands.valid_internal_dev_cmd?(cmd) if cmd
6667

@@ -96,8 +97,10 @@
9697
begin
9798
Homebrew.public_send Commands.method_name(cmd)
9899
rescue NoMethodError => e
99-
case_error = "undefined method `#{cmd.downcase}' for module Homebrew"
100-
odie "Unknown command: brew #{cmd}" if e.message == case_error
100+
converted_cmd = cmd.downcase.tr("-", "_")
101+
case_error = "undefined method `#{converted_cmd}' for module Homebrew"
102+
private_method_error = "private method `#{converted_cmd}' called for module Homebrew"
103+
odie "Unknown command: brew #{cmd}" if [case_error, private_method_error].include?(e.message)
101104

102105
raise
103106
end

Library/Homebrew/extend/kernel.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ module Kernel
88
def require?(path)
99
return false if path.nil?
1010

11-
require path
11+
if defined?(Warnings)
12+
# Work around require warning when done repeatedly:
13+
# https://bugs.ruby-lang.org/issues/21091
14+
Warnings.ignore(/already initialized constant/, /previous definition of/) do
15+
require path
16+
end
17+
else
18+
require path
19+
end
1220
true
1321
rescue LoadError => e
1422
# we should raise on syntax errors but not if the file doesn't exist.

0 commit comments

Comments
 (0)