Skip to content

Commit

Permalink
issue pallets#393: Show help hint only if there is a help option.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsiemens committed Apr 15, 2016
1 parent ddd8034 commit 2cae5e9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions click/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ class UsageError(ClickException):
def __init__(self, message, ctx=None):
ClickException.__init__(self, message)
self.ctx = ctx
self.cmd = self.ctx and self.ctx.command or None

def show(self, file=None):
if file is None:
file = get_text_stderr()
color = None
hint = ''
if (self.cmd is not None and
self.cmd.get_help_option(self.ctx) is not None):
hint = ('Try "%s %s" for help.\n'
% (self.ctx.command_path, self.ctx.help_option_names[0]))
if self.ctx is not None:
color = self.ctx.color
echo(self.ctx.get_usage() + '\nTry "%s %s" for help.\n'
% (self.ctx.command_path, self.ctx.help_option_names[0]),
file=file, color=color)
echo(self.ctx.get_usage() + '\n%s' % hint, file=file, color=color)
echo('Error: %s' % self.format_message(), file=file, color=color)


Expand Down

0 comments on commit 2cae5e9

Please sign in to comment.