Merge pull request #14652 from apainintheneck/improve-prof-errors

cmd/prof: improve error messages
This commit is contained in:
Kevin 2023-02-16 22:39:05 -08:00 committed by GitHub
commit 8ff2e29aad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,18 @@ module Homebrew
brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path
FileUtils.mkdir_p "prof"
cmd = args.named.first
raise UsageError, "#{cmd} is a Bash command!" if Commands.path(cmd).extname == ".sh"
case Commands.path(cmd)&.extname
when ".rb"
# expected file extension so we do nothing
when ".sh"
raise UsageError, <<~EOS
`#{cmd}` is a Bash command!
Try `hyperfine` for benchmarking instead.
EOS
else
raise UsageError, "`#{cmd}` is an unknown command!"
end
if args.stackprof?
Homebrew.install_gem_setup_path! "stackprof"
@ -45,5 +56,12 @@ module Homebrew
end
exec_browser output_filename
rescue OptionParser::InvalidOption => e
ofail e
# The invalid option could have been meant for the subcommand.
# Suggest `brew prof list -r` -> `brew prof -- list -r`
args = ARGV - ["--"]
puts "Try `brew prof -- #{args.join(" ")}` instead."
end
end