Hello hello!
I am fully aware that there are several parsing arguments libraries, but nevertheless it’s time for another one!
I wrote this due to my frustration with zig-clap api design, which I do not enjoy a lot, and I replicated EasyArgs’ brilliant idea of C’s preprocessor usage with a compile time struct generation! The idea is just to define what do you want to parse in an anonymous struct like this:
const definitions = .{
.required = .{
Arg(u32, "limit", "Limits are meant to be broken"),
Arg([]const u8, "username", "who are you dear?"),
},
.optional = .{
// type, field_name, short, default, description
OptArg(u32, "break", "b", 100, "Stop before the limit"),
},
.flag = .{
// default as false, type is bool
// field_name, short, description
Flag("verbose", "v", "Print a little, print a lot"),
}
};
const arguments: InputStruct = try parseArgs(allocator, definitions, stdout, stderr);
and then the compiler will generate a struct with those field names and fill them with whatever arguments you provided! :))
It just works on current master version of zig (0.16) due to the @Type function split up! Also idk how ergonomic it does feel, if you want to try it out or check the code and tell me pain points or bugs I would be very happy!
Thank you and have a nice day ![]()