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 c6536066dc39da653d265640c6ba6046bb5def98.
This commit is contained in:
parent
557ad956fd
commit
cf3486f98a
@ -40,6 +40,14 @@ module Homebrew
|
|||||||
path = command_path(cmd)
|
path = command_path(cmd)
|
||||||
end
|
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).
|
# Handle `brew` (no arguments).
|
||||||
if flags[:empty_argv]
|
if flags[:empty_argv]
|
||||||
$stderr.puts HOMEBREW_HELP
|
$stderr.puts HOMEBREW_HELP
|
||||||
|
|||||||
@ -118,8 +118,8 @@ rescue FormulaUnspecifiedError
|
|||||||
rescue KegUnspecifiedError
|
rescue KegUnspecifiedError
|
||||||
abort "This command requires a keg argument"
|
abort "This command requires a keg argument"
|
||||||
rescue UsageError
|
rescue UsageError
|
||||||
onoe "Invalid usage"
|
require "cmd/help"
|
||||||
abort ARGV.usage
|
Homebrew.help cmd, :usage_error => "Invalid usage"
|
||||||
rescue SystemExit => e
|
rescue SystemExit => e
|
||||||
onoe "Kernel.exit" if ARGV.verbose? && !e.success?
|
onoe "Kernel.exit" if ARGV.verbose? && !e.success?
|
||||||
$stderr.puts e.backtrace if ARGV.debug?
|
$stderr.puts e.backtrace if ARGV.debug?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user