Closed wizeman closed 3 years ago
Hi! Thanks for this report again. Same too: what distribution are you using? These things can be very distro-specific..
I'm using NixOS 20.09 but I think in this case it doesn't seem to be distro-specific, it seems to be a problem with the interface of this library.
Specifically, the Unknown_option
exception can only carry a char
, which means that if the user passed a --unknown-option
there is no way to know that easily or print a useful error message (as far as I can tell), because --unknown-option
doesn't fit on a char
. So this doesn't seem to be just an implementation bug, because there would be no way to solve it without changing the interface.
I was thinking it would be more useful if Unknown_option
would carry a string
rather than a char
. This way, you could pass the complete unknown option (including dash characters) in the exception so that the program could print an error message to the user.
On Linux, calling
getopt_long
when the user passed an unknown long option e.g.--non-existent
, theUnknown_option c
exception gets raised but thec
argument is just a zero.I understand this might be a limitation of the underlying getopt's interface, but I think different exception arguments should be used, otherwise there seems to be no way to know or print an error message indicating which option was invalid (also due to issue #3).
Alternatively, if the
Unknown_option
exception were to return the list of (unparsed?) arguments and the index of the invalid argument (probably based onoptind
?), then we could find out which option was invalid and print a useful error message.