Adds demo.

This commit is contained in:
Felix (xq) Queißner 2020-03-04 22:38:26 +01:00
parent 1d1179ee9e
commit 94c96afcdd
2 changed files with 27 additions and 0 deletions

View File

@ -1,2 +1,27 @@
# zig-args
Simple-to-use argument parser with struct-based config
```zig
const options = try argsParser.parse(struct {
// This declares long options for double hyphen
output: ?[]const u8 = null,
@"with-offset": bool = false,
@"with-hexdump": bool = false,
@"intermix-source": bool = false,
numberOfBytes: ?i32 = null,
// This declares short-hand options for single hyphen
pub const shorthands = .{
.S = "intermix-source",
.b = "with-hexdump",
.O = "with-offset",
.o = "output",
};
}, &args, argsAllocator);
defer options.deinit();
std.debug.warn("parsed result:\n{}\npositionals:\n", .{options.options});
for (options.args) |arg| {
std.debug.warn("\t{}\n", .{arg});
}
```

View File

@ -13,12 +13,14 @@ pub fn main() !void {
defer argsAllocator.free(exeName);
const options = try argsParser.parse(struct {
// This declares long options for double hyphen
output: ?[]const u8 = null,
@"with-offset": bool = false,
@"with-hexdump": bool = false,
@"intermix-source": bool = false,
numberOfBytes: ?i32 = null,
// This declares short-hand options for single hyphen
pub const shorthands = .{
.S = "intermix-source",
.b = "with-hexdump",