Double enclosed appendable params #48

puzrin opened this Issue Feb 15, 2013 · 3 comments

2 participants

Nodeca member

I've noticed, that new argparse releases completely fuckuped our ndoc.

Input data (process.argv):

[ 'node',
  'examples/' ]

argparse config:

cli.addArgument(['paths'], {
  help:         'Source files location',
  metavar:      'PATH',
  action:       'append',
  nargs:        '+'


{ paths: [ [ 'lib/', 'examples/' ] ], use: [] }

Note, that paths become double stacked array. It should be just simple array of strings. It was ok in 1.0.3


Python argparse produces the same results.

I'd have dig deeper on this, but I don't think that 'append' is meant to work with positional arguments.

A couple of things that work are:

cli.addArgument{['paths'],{nargs: "+"})


cli.addArgument(['-p', '--paths'], {action: 'append'})
cli.parseArgs(['-p', 'lib/', '-p', 'examples/'])

The 1st test in positionals.js is the only test derived from python that combines positionals and append.

cli.addArgument(['paths'], {action: 'append'});
cli.addArgument(['paths'], {action: 'append'});

also works (for only 2 items).


It was issue #37 that change the behavior of append.

with nargs='+', all of the positional arguments are collected into an array, and then append 'pushes' this onto the default value ([]), producing the nested arrays. Previously append used concat, but 'push' matches the Python 'append'.

Unless you need to concat the new values to a preexisting array of values, nargs '+' together with the default store action should do the job.

Nodeca member

Solved. That was ndoc error. Thanks for your advices, Paul.

@puzrin puzrin closed this Feb 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment