zopt: low-ceremony command line parsing for Zig

29 points by hgrsd


fanf

I couldn’t see in the examples how can a program report an error when the user passes an unknown option?

The short option syntax doesn’t follow the traditional unix / POSIX syntax which treats -f arg or -farg the same. (Sadly this is a fairly common bug.) The standard syntax requires that the option parser is told whether a flag takes an argument before it continues parsing after the flag, so that it can tell the difference between grouped flags and a flag with argument. (It’s possible to tell a lexopt-style parser that an argument is expected immediately after it parses the flag, but that’s the latest possible moment. Traditionally the parser gets told at the earliest possible moment, before it starts.)