Skip to content

Multiple identical arguments to satisfy a list option #5

Open
@ganeshv

Description

@ganeshv

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions