Skip to content
Snippets Groups Projects
Commit cf3486f9 authored by Martin Afanasjew's avatar Martin Afanasjew
Browse files

help: show command-specific help for invalid usage

Instead of always printing the generic help text, print command-specific
help if it is available and a command raised the `UsageError` exception.
Put the error message underneath the help text (was above) to avoid that
it scrolls off the screen.

Thereby fix a regression where handling the invalid usage would fail to
access `ARGV.usage` removed in c6536066.
parent 557ad956
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,14 @@ module Homebrew
path = command_path(cmd)
end
# Display command-specific (or generic) help in response to `UsageError`.
if (error_message = flags[:usage_error])
$stderr.puts path ? command_help(path) : HOMEBREW_HELP
$stderr.puts
onoe error_message
exit 1
end
# Handle `brew` (no arguments).
if flags[:empty_argv]
$stderr.puts HOMEBREW_HELP
......
......@@ -118,8 +118,8 @@ rescue FormulaUnspecifiedError
rescue KegUnspecifiedError
abort "This command requires a keg argument"
rescue UsageError
onoe "Invalid usage"
abort ARGV.usage
require "cmd/help"
Homebrew.help cmd, :usage_error => "Invalid usage"
rescue SystemExit => e
onoe "Kernel.exit" if ARGV.verbose? && !e.success?
$stderr.puts e.backtrace if ARGV.debug?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment