`parseHelps` fails on a single element
ZoomRmc opened this issue ยท 6 comments
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
Reproduced. Temporary workaround is to inline the {}
into the dispatch
call, as in
dispatch(fun, help = { "foo": "foooo" })
in your example.
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
.
Huh, this looks obvious in hindsight until you ask yourself why does this work with multiple elements without the import. :)
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.
Please, reopen and assign me to update the docs.