Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple identical arguments to satisfy a list option #5

Open
ganeshv opened this issue Nov 10, 2012 · 1 comment
Open

Multiple identical arguments to satisfy a list option #5

ganeshv opened this issue Nov 10, 2012 · 1 comment

Comments

@ganeshv
Copy link

ganeshv commented Nov 10, 2012

Giving multiple identical arguments to something like [<item>...] returns only one instance of the argument. python docopt does the right thing. Example:

usage = """
Usage:
    echo [<item>...]
"""
{docopt} = require '../docopt'
console.log docopt(usage, version: '2.0')

Now, coffee bug.coffee a a a returns
{ '<item>': [ 'a' ] }
whereas it really ought to return
{ '<item>': [ 'a', 'a', 'a' ] }

The problem is with this line in the Argument class:
left = (l for l in left when l.toString() isnt args[0].toString())
which will take out every instance matching args[0] when it really ought to remove only the first one, like in the python implementation.

I changed it as follows to make it work

-        left = (l for l in left when l.toString() isnt args[0].toString())
+        idx = left.indexOf args[0]
+        left = left.slice(0, idx).concat(left.slice(idx + 1))

but I don't know coffeescript so maybe there's a better way of doing it.

@valeriangalliat
Copy link

I also encountered this issue when two arguments have the same value, for example:

Usage: foo [options] <input> <output>

Options:
  --test

The program will exit and show help if I call it with foo test test, but will work with foo --test test test or foo test something.

kemitchell pushed a commit to kemitchell/docopt.coffee that referenced this issue Jul 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants