mirror of
https://github.com/gosticks/brew.git
synced 2026-08-12 12:40:22 +00:00
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 c6536066dc.
This commit is contained in:
@@ -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
|
||||
|
||||
+2
-2
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user