Skip to content

Commit b89ad6b

Browse files
committed
Add option for #557
1 parent ae5386b commit b89ad6b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

click/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,15 @@ class Command(BaseCommand):
737737
shown on the command listing of the parent command.
738738
:param add_help_option: by default each command registers a ``--help``
739739
option. This can be disabled by this parameter.
740+
:param hint_help: by default the ``--help`` is mentioned in usage errors.
741+
This can be disabled by this parameter.
740742
:param hidden: hide this command from help outputs.
741743
"""
742744

743745
def __init__(self, name, context_settings=None, callback=None,
744746
params=None, help=None, epilog=None, short_help=None,
745747
options_metavar='[OPTIONS]', add_help_option=True,
746-
hidden=False):
748+
hint_help=True, hidden=False):
747749
BaseCommand.__init__(self, name, context_settings)
748750
#: the callback to execute when the command fires. This might be
749751
#: `None` in which case nothing happens.
@@ -759,6 +761,7 @@ def __init__(self, name, context_settings=None, callback=None,
759761
short_help = make_default_short_help(help)
760762
self.short_help = short_help
761763
self.add_help_option = add_help_option
764+
self.hint_help = hint_help
762765
self.hidden = hidden
763766

764767
def get_usage(self, ctx):

click/exceptions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ def show(self, file=None):
5151
file = get_text_stderr()
5252
color = None
5353
hint = ''
54-
if (self.cmd is not None and
55-
self.cmd.get_help_option(self.ctx) is not None):
54+
if (
55+
self.cmd is not None and
56+
self.cmd.hint_help and
57+
self.cmd.get_help_option(self.ctx) is not None
58+
):
5659
hint = ('Try "%s %s" for help.\n'
5760
% (self.ctx.command_path, self.ctx.help_option_names[0]))
5861
if self.ctx is not None:

tests/test_formatting.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,14 @@ def cmd(arg):
212212
'',
213213
'Error: Missing argument "arg".'
214214
]
215+
216+
217+
def test_formatting_usage_error_no_hints(runner):
218+
@click.command(hint_help=False)
219+
@click.argument('arg')
220+
def cmd(arg):
221+
click.echo('arg:' + arg)
222+
223+
result = runner.invoke(cmd, [])
224+
assert result.exit_code == 2
225+
assert "--help" not in result.output

0 commit comments

Comments
 (0)