From d216b3355dd1559ead42f05752a12f96ad6fb4e2 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Wed, 15 Feb 2023 00:50:21 -0800 Subject: [PATCH] cmd/prof: improve error messages - Provide an error message when the command is unknown. - Suggest running the command again with `--` if there is an invalid option which might have been meant for a subcommand. --- Library/Homebrew/dev-cmd/prof.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/prof.rb b/Library/Homebrew/dev-cmd/prof.rb index 4a1f5e5ae0..0b595e9113 100644 --- a/Library/Homebrew/dev-cmd/prof.rb +++ b/Library/Homebrew/dev-cmd/prof.rb @@ -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