Skip to content

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

Open

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

`

Activity

  1. fsparv commented on Jan 20, 2023

    @fsparv

    Yeah, but some programs do use numbers as options (i.e less in linux command line).

    
           -# or --shift
                  Specifies the default number of positions to scroll
                  horizontally in the RIGHTARROW and LEFTARROW commands.  If
                  the number specified is zero, it sets the default number
                  of positions to one half of the screen width.
                  Alternately, the number may be specified as a fraction of
                  the width of the screen, starting with a decimal point: .5
                  is half of the screen width, .3 is three tenths of the
                  screen width, and so on.  If the number is specified as a
                  fraction, the actual number of scroll positions is
                  recalculated if the terminal window is resized, so that
                  the actual scroll remains at the specified fraction of the
                  screen width.
    
    

    Your change could break things for existing programs, and leave them no options other than forking docopt, removing docopt or breaking back compatibility on their software.

    I'd vote -1 on this (if there was voting on this project)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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