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

"Bad enum value" response starts to and then doesn't list alternatives to the empty string #220

Closed jrfondren closed 1 year ago

jrfondren commented 1 year ago

This program:

import cligen

type E = enum
  A, B, C

proc bug(e: E) =
  echo e

dispatch bug

Responds with "one of: \<nothing>" when a bad -e is provided:

$ ./example -e
Bad enum value for option "e". "" is not one of:

Maybe you meant one of:

Run with --help for more details.
$ ./example -e=
Bad enum value for option "e". "" is not one of:

Maybe you meant one of:

Run with --help for more details.
$ ./example -e=?
Bad enum value for option "e". "?" is not one of:
  A B C

Maybe you meant one of:
  A
  B
  C

Bonus

There's probably no helping this one:

import cligen

type E = enum
  A = ""
  B = "B"
  C = "C"

proc bug(e: E) =
  echo e

dispatch bug

usage:

$ ./example -e=A
Bad enum value for option "e". "A" is not one of:
   B C

Maybe you meant one of:

  B
  C

Run with --help for more details.
$ ./example -e=""
Bad enum value for option "e". "" is not one of:

Maybe you meant one of:

Run with --help for more details.
c-blake commented 1 year ago

Thanks for the report. I have reproduced this and will look at it in the coming hours.

c-blake commented 1 year ago

I think the current version control HEAD should work (even for your rather pathological empty enum string) case on Nim-0.20.2 up to nim-devel. E.g.,

type E = enum A = "", B = "B", C = "C"
proc bug(e: E) = echo len($e)
import cligen; dispatch bug
$ ./bug2 -e '' # produces "0\n"

If you need a release to test (e.g. via nimble) then I could punch one, but I'd probably prefer to wait a week or two. Let me know.