c-blake / cligen

Nim library to infer/generate command-line-interfaces / option / argument parsing; Docs at
https://c-blake.github.io/cligen/
ISC License
496 stars 23 forks source link

`parseHelps` fails on a single element #194

Closed ZoomRmc closed 3 years ago

ZoomRmc commented 3 years ago
import cligen
const Help = { "foo": "foooo" }
proc fun(foo = 1):int =
  result = 1

dispatch(fun, help = Help)

cligen-1.5.4/cligen.nim(195, 32) Error: index 1 not in 0 .. 0

Adding bogus entries for params not present in the proc results in Help being ignored.

Nim: 1.5.1 cligen: 1.5.4

c-blake commented 3 years ago

Reproduced. Temporary workaround is to inline the {} into the dispatch call, as in

dispatch(fun, help = { "foo": "foooo" })

in your example.

c-blake commented 3 years ago

Actually, this works already - you just need to import tables and put a toTable after the closing brace }. My thinking here was that it is better to have a typed parameter that is more explicit about de-duplication than the [(key,val),...] list. Sorry for not catching this earlier. The test program for this is test/PassValues.nim.

ZoomRmc commented 3 years ago

Huh, this looks obvious in hindsight until you ask yourself why does this work with multiple elements without the import. :)

c-blake commented 3 years ago

I agree...That's also what tricked me..but it does not actually work. If you do multiple elements, things compile & run, but they do not run correctly. The help output is "set foo" or "set bar" or whatever multiple param names, not the requested text of "foooo" in your example. I agree it would be better to fail/produce a better error message on CLauthor-misuse here, but you are the first who reported such. So, not sure how common it is.

ZoomRmc commented 3 years ago

Please, reopen and assign me to update the docs.

c-blake commented 3 years ago

@ZoomRmc will do a PR updating docs { somewhere..anywhere :-) } to re-close this.