Skip to content

Commit 2cae5e9

Browse files
committed
issue pallets#393: Show help hint only if there is a help option.
1 parent ddd8034 commit 2cae5e9

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎click/exceptions.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ class UsageError(ClickException):
4444
def __init__(self, message, ctx=None):
4545
ClickException.__init__(self, message)
4646
self.ctx = ctx
47+
self.cmd = self.ctx and self.ctx.command or None
4748

4849
def show(self, file=None):
4950
if file is None:
5051
file = get_text_stderr()
5152
color = None
53+
hint = ''
54+
if (self.cmd is not None and
55+
self.cmd.get_help_option(self.ctx) is not None):
56+
hint = ('Try "%s %s" for help.\n'
57+
% (self.ctx.command_path, self.ctx.help_option_names[0]))
5258
if self.ctx is not None:
5359
color = self.ctx.color
54-
echo(self.ctx.get_usage() + '\nTry "%s %s" for help.\n'
55-
% (self.ctx.command_path, self.ctx.help_option_names[0]),
56-
file=file, color=color)
60+
echo(self.ctx.get_usage() + '\n%s' % hint, file=file, color=color)
5761
echo('Error: %s' % self.format_message(), file=file, color=color)
5862

5963

0 commit comments

Comments
 (0)