Open bluenote10 opened 4 years ago
This would be nice, I agree. It's not currently possible. I haven't done it yet because I don't know the best way to do it.
For instance, the Nim proc that changes a string to an int is parseInt
, so should the argument use type=parseInt
? If so, it'll have to figure out how to extract the return type of that function so that the opts
object has the right type.
Another option would be to require people to pass both type=int
and validator=parseInt
. That would be easier for argparse
but maybe not as nice for users?
I would simply go for parser=parseInt
. It should be possible to infer the return type statically by something like type(parser(""))
.
In my opinion, the keyword parser
might be more appropriate than copying Python's type=...
because
string => T
function with the possibility of failed parsing,parseX
functions.
First of all: Great project! Finally writing CLIs will become convenient in Nim ;).
I was wondering if it is possible to have type converters / custom validators similar to Python/argparse's
type
that can be used for use cases like:float
.It would be nice if these use cases would not require a manual post-parsers validation + convert. Is that already possible?