Skip to content

Commit

Permalink
Add option for #557
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Apr 15, 2016
1 parent ae5386b commit b89ad6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,13 +737,15 @@ class Command(BaseCommand):
shown on the command listing of the parent command.
:param add_help_option: by default each command registers a ``--help``
option. This can be disabled by this parameter.
:param hint_help: by default the ``--help`` is mentioned in usage errors.
This can be disabled by this parameter.
:param hidden: hide this command from help outputs.
"""

def __init__(self, name, context_settings=None, callback=None,
params=None, help=None, epilog=None, short_help=None,
options_metavar='[OPTIONS]', add_help_option=True,
hidden=False):
hint_help=True, hidden=False):
BaseCommand.__init__(self, name, context_settings)
#: the callback to execute when the command fires. This might be
#: `None` in which case nothing happens.
Expand All @@ -759,6 +761,7 @@ def __init__(self, name, context_settings=None, callback=None,
short_help = make_default_short_help(help)
self.short_help = short_help
self.add_help_option = add_help_option
self.hint_help = hint_help
self.hidden = hidden

def get_usage(self, ctx):
Expand Down
7 changes: 5 additions & 2 deletions click/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ def show(self, file=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):
if (
self.cmd is not None and
self.cmd.hint_help 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:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,14 @@ def cmd(arg):
'',
'Error: Missing argument "arg".'
]


def test_formatting_usage_error_no_hints(runner):
@click.command(hint_help=False)
@click.argument('arg')
def cmd(arg):
click.echo('arg:' + arg)

result = runner.invoke(cmd, [])
assert result.exit_code == 2
assert "--help" not in result.output

0 comments on commit b89ad6b

Please sign in to comment.