Reokodoku/sap
A simple argument parser library for zig
sap is a simple argument parser library for zig that uses a tuple of flags to create a struct containing the value of the arguments.
zig fetch --save git+https://github.com/Reokodoku/sap
build.zig
:const sap = b.dependency("sap", .{});
exe.root_module.addImport("sap", sap.module("sap"));
Minimal example:
const sap = @import("sap");
var arg_parser = sap.Parser(.{
sap.flag([]const u8, "hello", 'h', "world"),
}).init(allocator);
defer arg_parser.deinit();
const args = try arg_parser.parseArgs();
std.debug.print("Executable name: {s}\n", .{args.executable_name});
var positionals_iter = args.positionals.iterator();
std.debug.print("Positionals:\n", .{});
while (positionals_iter.next()) |str|
std.debug.print(" {s}\n", .{str});
std.debug.print("`hello`|`h` flag value: {s}\n", .{args.hello});
You can find more examples in the examples/
folder.
For more information, see the source code or documentation (zig build docs
).
--foo=bar
) or a space (--foo bar
)?bool
, ?[]const u8
, ...)sap targets the master branch of zig.
In the build.zig.zon
file, there is the minimum_zig_version
field which specifies the latest version of zig in which sap compiles.
When the zig master branch breaks the compilation, a commit will be merged to:
minimum_zig_version
field with the new zig version