Skip to content
Myr

Only allow one param decl for Arguments

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

authored by Robert Grant · committed by Robert Grant · parent 1dee255 · Browse files · 2 files+12 added−6 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+12 added−6 removed

  • tests:+9 added−0 removed
  • other:+3 added−6 removed

2 files+12 added−6 removed

modified:click/core.py+3 added-6 removed
1322 unmodified lines
1323 self.default = default1324 self.is_eager = is_eager1325 self.metavar = metavar1326 self.envvar = envvar1327 self.autocompletion = autocompletion1327 self.autocompletion = autocompletion13281329 @property1330 def human_readable_name(self):1331 """Returns the human readable name of this parameter. This is the
22 unmodified lines
13541355 def add_to_parser(self, parser, ctx):1356 pass135713581358 def consume_value(self, ctx, opts):1359 value = opts.get(self.name)1360 if value is None:1361 value = self.value_from_envvar(ctx)
441 unmodified lines
1803 raise TypeError('Could not determine name for argument')1804 if len(decls) == 1:1805 name = arg = decls[0]1806 name = name.replace('-', '_').lower()1808 elif len(decls) == 2:1809 name, arg = decls1807 else:1811 raise TypeError('Arguments take exactly one or two '1812 'parameter declarations, got %d' % len(decls))1808 raise TypeError('Arguments take exactly one '1809 'parameter declaration, got %d' % len(decls))1810 return name, [arg], []18111812 def get_usage_pieces(self, ctx):1813 return [self.make_metavar()]
11 unmodified lines
modified:tests/test_arguments.py+9 added
1# -*- coding: utf-8 -*-2import pytest3import click4from click._compat import PY256
280 unmodified lines
287288 result = runner.invoke(cmd, ['3'])289 assert result.exception is not None290 assert 'argument a takes 2 values' in result.output291292293@pytest.mark.xfail294def test_multiple_param_decls_not_allowed(runner):295 @click.command()296 @click.argument('x', click.Choice(['a', 'b']))297 def copy(x):298 click.echo(x)