Closed mrkline closed 4 years ago
Yes, I think the "asLong" function should be renamed.
The official 'docopt' version doesnt try to create numbers out of arguments; the numbers only happen on presence/counting args (eg, "--help" or "-vvv"). I think we should rename this so that it's clear what is happening.
I think this is stale now that #28 is integrated. Please reopen if you disagree.
Integer arguments are always parsed by
docopt::docopt
as strings. For example:throws, giving
By the principle of least astonishment, I would think that calling
asLong
on an integral argument would give me a long with no hassle. But some quick inspection of docopt_value.h and docopt.cpp shows that the value's internal union is fed a string, andtoLong
throws its hands up instead of attempting some conversion.Forgive me if I'm missing something obvious (as I haven't dug through the code thoroughly). Is this expected behavior? Of course you can always parse the values yourself with
istringstream
orsscanf
, but doing so is a bit of a pain, especially for a library focused on simplicity and expressiveness.