docopt / docopt.go

A command-line arguments parser that will make you smile.
http://docopt.org/
MIT License
1.43k stars 111 forks source link

Parsing errors #54

Closed petemoore closed 6 years ago

petemoore commented 6 years ago

Something not quite right here:

$ taskcluster-proxy -h
Usage: taskcluster-proxy [(-p|--port) <port>] [--client-id <clientId> --access-token <accessToken> [--certificate <certificate>]] ([-a|--all-scopes]|([-t|--task-id <taskId>] [-s|--scopes <scope>...]))
$ taskcluster-proxy -p 4 --access-token 43434

2018/03/01 19:44:01 {
  "--access-token": true,
  "--all-scopes": false,
  "--certificate": false,
  "--client-id": false,
  "--port": false,
  "--scopes": false,
  "--task-id": false,
  "-a": false,
  "-p": true,
  "-s": false,
  "-t": false,
  "\u003caccessToken\u003e": null,
  "\u003ccertificate\u003e": null,
  "\u003cclientId\u003e": "43434",
  "\u003cport\u003e": "4",
  "\u003cscope\u003e": [],
  "\u003ctaskId\u003e": null
}

As you see, the parsing should not succeed, since --access-token is specified without --client-id, yet the parsing succeeds, and assigns the access token to the <clientId> property.

fenollp commented 6 years ago

From what I gather from the website you need to wrap the innards of [] with ()

petemoore commented 6 years ago

Many thanks @fenollp, indeed it does seem to work with: taskcluster-proxy [((-p|--port) <port>)] [(--client-id <clientId> --access-token <accessToken> [(--certificate <certificate>)])] ([(-a|--all-scopes)]|([((-t|--task-id) <taskId>)] [((-s|--scopes) <scope>...)])).

Certainly this makes it a lot less readable - it would seem reasonable to me if docopt was to internally replace the innards of [] with (). I appreciate this is just the go implementation, so the responsibility probably lies with the parent project.

In any case thanks for highlighting the issue for me, and hopefully one day this requirement will be dropped.