Skip to content
Myr

issue #393: Usage error should show there is a --help option

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ryan Siemens · committed by Ryan Siemens · parent cdea8fc · Browse files · 2 files+38 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+38 added−1 removed

  • tests:+35 added−0 removed
  • other:+3 added−1 removed

2 files+38 added−1 removed

modified:click/exceptions.py+3 added-1 removed
49 unmodified lines
50 file = get_text_stderr()51 color = None52 if self.ctx is not None:53 color = self.ctx.color54 echo(self.ctx.get_usage() + '\n', file=file, color=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)57 echo('Error: %s' % self.format_message(), file=file, color=color)585960class BadParameter(UsageError):
153 unmodified lines
modified:tests/test_formatting.py+35 added
143 unmodified lines
144 '',145 'Options:',146 ' --help Show this message and exit.',147 ]148149150def test_formatting_usage_error(runner):151 @click.command()152 @click.argument('arg')153 def cmd(arg):154 click.echo('arg:' + arg)155156 result = runner.invoke(cmd, [])157 assert result.exit_code == 2158 assert result.output.splitlines() == [159 'Usage: cmd [OPTIONS] ARG',160 'Try "cmd --help" for help.',161 '',162 'Error: Missing argument "arg".'163 ]164165166def test_formatting_usage_error_nested(runner):167 @click.group()168 def cmd():169 pass170171 @cmd.command()172 @click.argument('bar')173 def foo(bar):174 click.echo('foo:' + bar)175176 result = runner.invoke(cmd, ['foo'])177 assert result.output.splitlines() == [178 'Usage: cmd foo [OPTIONS] BAR',179 'Try "cmd foo --help" for help.',180 '',181 'Error: Missing argument "bar".'182 ]