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

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

Open
stebecca opened this issue Dec 21, 2022 · 1 comment

Comments

@stebecca
Copy link

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

`

@fsparv
Copy link

fsparv commented Jan 20, 2023

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants