summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2014-05-29 02:50:41 +0600
committerArmin Ronacher <armin.ronacher@active-4.com>2014-05-29 02:50:41 +0600
commita6af25df9c2e82e94c3aa15d579f9347881e5efb (patch)
tree036bc14bbc4f83bec974e055fdb04e5e0385ad6a
parentc7299c431933db47c9fab6771e34a9dd46a09415 (diff)
downloadclick-a6af25df9c2e82e94c3aa15d579f9347881e5efb.tar.gz
Fixed a bug in argument handling
-rw-r--r--click/core.py2
-rw-r--r--tests/test_arguments.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/click/core.py b/click/core.py
index c0a17f4..e64e57c 100644
--- a/click/core.py
+++ b/click/core.py
@@ -1173,7 +1173,7 @@ class Argument(Parameter):
if attrs.get('default') is not None:
required = False
else:
- required = attrs.get('nargs', 0) > 0
+ required = attrs.get('nargs', 1) > 0
Parameter.__init__(self, param_decls, required=required, **attrs)
def make_metavar(self):
diff --git a/tests/test_arguments.py b/tests/test_arguments.py
index 681c5b9..3f936ed 100644
--- a/tests/test_arguments.py
+++ b/tests/test_arguments.py
@@ -145,6 +145,17 @@ def test_empty_nargs(runner):
assert 'Missing argument "arg"' in result.output
+def test_missing_arg(runner):
+ @click.command()
+ @click.argument('arg')
+ def cmd(arg):
+ click.echo('arg:' + arg)
+
+ result = runner.invoke(cmd, [])
+ assert result.exit_code == 2
+ assert 'Missing argument "arg".' in result.output
+
+
def test_implicit_non_required(runner):
@click.command()
@click.argument('f', default='test')