Skip to content

Commit

Permalink
Add test from #612 for usage error Argument format
Browse files Browse the repository at this point in the history
Adds a test that ensures that when an Argument is formatted into a usage
error, its metavar is used, not its name.
Additionally, repair testsuite to expect the new behavior.
  • Loading branch information
sirosen committed Dec 30, 2016
1 parent fe58ed3 commit e61053a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ def get_usage_pieces(self, ctx):
return [self.make_metavar()]

def get_error_hint(self, ctx):
return self.make_metavar()
return '"%s"' % self.make_metavar()

def add_to_parser(self, parser, ctx):
parser.add_argument(dest=self.name, nargs=self.nargs,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def cmd2(arg):

result = runner.invoke(cmd2, [])
assert result.exit_code == 2
assert 'Missing argument "arg"' in result.output
assert 'Missing argument "ARG..."' in result.output


def test_missing_arg(runner):
Expand All @@ -199,7 +199,7 @@ def cmd(arg):

result = runner.invoke(cmd, [])
assert result.exit_code == 2
assert 'Missing argument "arg".' in result.output
assert 'Missing argument "ARG".' in result.output


def test_implicit_non_required(runner):
Expand Down
28 changes: 24 additions & 4 deletions tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,27 @@ def cmd(arg):
'Usage: cmd [OPTIONS] ARG',
'Try "cmd --help" for help.',
'',
'Error: Missing argument "arg".'
'Error: Missing argument "ARG".'
]


def test_formatting_usage_error_metavar(runner):
"""
:author: @r-m-n
Including attribution to #612
"""
@click.command()
@click.argument('arg', metavar='metavar')
def cmd(arg):
pass

result = runner.invoke(cmd, [])
assert result.exit_code == 2
assert result.output.splitlines() == [
'Usage: cmd [OPTIONS] metavar',
'Try "cmd --help" for help.',
'',
'Error: Missing argument "metavar".'
]


Expand All @@ -179,7 +199,7 @@ def foo(bar):
'Usage: cmd foo [OPTIONS] BAR',
'Try "cmd foo --help" for help.',
'',
'Error: Missing argument "bar".'
'Error: Missing argument "BAR".'
]


Expand All @@ -194,7 +214,7 @@ def cmd(arg):
assert result.output.splitlines() == [
'Usage: cmd [OPTIONS] ARG',
'',
'Error: Missing argument "arg".'
'Error: Missing argument "ARG".'
]


Expand All @@ -210,5 +230,5 @@ def cmd(arg):
'Usage: cmd [OPTIONS] ARG',
'Try "cmd --man" for help.',
'',
'Error: Missing argument "arg".'
'Error: Missing argument "ARG".'
]

0 comments on commit e61053a

Please sign in to comment.