Sourceopt - argument parser with pluggable "sources"

Hey!

I’ve seen a lot of argument parsing libraries pop up recently, so I’m sorry for the poor timing on this. I wrote some code many months ago and kind of forgot about it, until I recently needed to use it myself.

This is an argument parsing library that wants to put all decision making on the user. I dislike it when argument parsers print things for me, I generally want to be in control of everything my program sends to stdout, so this library is careful not to do that. In other words, the end user should not be able to notice your usage of the library.

It has two concepts: Setter and Source. A Setter is a vtable that tells the parser how to convert a []const u8 to some type, and then writes it to a pointer. A Source is a vtable that the parser uses to find values for flags that were not provided as arguments.

I imagine people writing their own Setter and Source implementations, but some built-ins are included, mostly as examples.

It works by first processing all arguments from some kind of iterator that you provide. For the remaining flags that did not receive a value, it will call the sources in order until it finds one or has exhausted all sources.

It has worked well for me so far. If you read the code and spot any problems, please let me know. Maybe open an issue.

Thanks!

6 Likes