Skip to content

Commit

Permalink
Fix nargs
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Sep 15, 2018
1 parent 2483928 commit 8680dbe
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions julia/pseudo_python_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ def _add_argument_impl(self, name, alt, dest=None, nargs=None, action=None,
raise TypeError("`nargs` and `action` are mutually exclusive")
if action == "store_true":
nargs = 0
if nargs is None:
nargs = 1
assert isinstance(nargs, int)
assert nargs is None or isinstance(nargs, int)
assert action in (None, "store_true")

assert dest not in self._dests
Expand Down Expand Up @@ -199,7 +197,10 @@ def _parse_until_terminal(self, ns, args_iter):
.format(", ".join(res.option.argdest.names)))
seen.add(dest)

while len(res.values) < res.option.nargs:
num_args = res.option.nargs
if num_args is None:
num_args = 1
while len(res.values) < num_args:
try:
res.values.append(next(args_iter))
except StopIteration:
Expand All @@ -209,7 +210,7 @@ def _parse_until_terminal(self, ns, args_iter):
setattr(ns, dest, True)
else:
value = res.values
if res.option.nargs == 1:
if res.option.nargs is None:
value, = value
setattr(ns, dest, value)

Expand All @@ -233,7 +234,7 @@ def _find_matches(self, arg):
if opt.is_long and arg[len(opt.name)] == "=":
return [Result(opt, [arg[len(opt.name) + 1:]])]
elif not opt.is_long:
if opt.nargs > 0:
if opt.nargs != 0:
return [Result(opt, [arg[len(opt.name):]])]
else:
results = [Result(opt, [])]
Expand Down

0 comments on commit 8680dbe

Please sign in to comment.