On Wednesday, 9 April 2025 at 01:23:01 UTC, Salih Dincer wrote:
On Tuesday, 8 April 2025 at 20:14:56 UTC, Andy Valencia wrote:

p.s. Ironically, I could probably have coded a getopt in less time than I've spent on std.getopt...

:)

Please try the following example with the parameters -h, -e, -l, and -v in that order:

-h prints what one expects. If help is wanted I expect the usage info be written on stdout though. Nothing bothers more than programs with multiple pages of usage help written you cannot pipe cleanly to less.

-e says "-h --help This help information" which is not really true, since "This" help information is the help information of the empty list of the second getopt call in line 37 of your code and not the help for the original list.

-l crashes with a stack trace after getopt threw in line 37 (Unrecognized option -l). This crash happens because -l is not removed from args.

-v does as expected.

That your program prints what it prints in the -e case is due to the fact that in the second getopt call (line 37) the -e flag has already been removed from the original args array. If you put the throw block into a function (clean code) that mechanism no longer works.

my 2ยข

Reply via email to