docopt.hs icon indicating copy to clipboard operation
docopt.hs copied to clipboard

Inconsistencies in ambiguity resolution

Open gdetrez opened this issue 10 years ago • 1 comments

While filing up #18, I found a small inconsistency in the way ambiguities are resolved. According to docopt.org:

Note, writing --input ARG (opposed to --input=ARG) is ambiguous, meaning it is not possible to tell whether ARG is option's argument or positional argument. In usage patterns this will be interpreted as option with argument only if option's description (covered below) for that option is provided. Otherwise it will be interpreted as separate option and positional argument.

So, if you take the following

Usage:
  test --input ARG

and call it with --input foo you'd expect:

fromList [(LongOption "input",Present),(Argument "ARG",Value "foo")]

but you get

fromList [(LongOption "input",Value "foo")]

Even providing the correct option description doesn't get the intended behavior:

Usage:
  test --input ARG
Options:
  --input
$ test --input foo
fromList [(LongOption "input",Value "foo")]

Disambiguating it the other way gives you something even stranger:

Usage:
  test --input ARG
Options:
  --input ARG
$ test --input foo
fromList [(LongOption "input",Value "foo"),(Argument "ARG",NoValue)]

gdetrez avatar Jul 13 '15 10:07 gdetrez

I've played a bit more with ambiguous options, there are similar problems with short options:

Usage:
  foo -f ARG
$ foo -f bar
fromList [(ShortOption 'f',Value "bar")]
# Expected: fromList [(ShortOption 'f',Present),(Argument "ARG",Value "bar")]

Usage:
  foo -f ARG
Options:
  -f
$ foo -f bar
fromList [(ShortOption 'f',Value "bar")]
# Expected: fromList [(ShortOption 'f',Present),(Argument "ARG",Value "bar")]

$ foo
fromList [(ShortOption 'f',NoValue)] 
# Expected: Usage: ...

Usage:
  foo -f ARG
Options:
  -f ARG
foo -f bar
fromList [(ShortOption 'f',Value "bar"),(Argument "ARG",NoValue)]
# Expected: fromList [(ShortOption 'f',Value "bar")]

with

Usage:
  foo -fARG
Options:
  -fARG
$ foo -fbar
Usage:
  foo -fARG
Options:
  -fARG
# Expected: fromList [(ShortOption 'f',Value "bar")]

$ foo
fromList [(ShortOption 'A',NotPresent),(ShortOption 'G',NotPresent),(ShortOption 'R',NotPresent),(ShortOption 'f',NotPresent)]
# Expected: Usage: ...

gdetrez avatar Jul 13 '15 11:07 gdetrez