Skip to content

Patch to allow negative numbers as arguments without having to set options-first (--) option #14

@stebecca

Description

@stebecca

This patch allows an argument that matches the regex /\-\d/ not to be recognized as an "option" and treated as an "argument" instead. Normally this does not work unless you set the options-first (--) parameter before the argument in question. Since options do not normally start with a number, this provides a simple fix to this common problem.
For example if one has a Docopt entry:
rectangle <x1> <y1> <x2> <y2>
This will not work if any of the arguments are negative numbers since the negative number would be treated as an option.
The only solution would be:
rectangle -- <x1> <y1> <x2> <y2>
which is inconvenient.

The following simple patch fixes this issue.

In Docopt.java:
`455a456,458

                      if(tokens.current().matches("^\\-\\d"))
                          parsed.add(new Argument(null, tokens.move()));
                      else

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions