From 94c96afcdd57139e1dc980caaf707dbb420aadbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20=28xq=29=20Quei=C3=9Fner?= Date: Wed, 4 Mar 2020 22:38:26 +0100 Subject: [PATCH] Adds demo. --- README.md | 25 +++++++++++++++++++++++++ demo.zig | 2 ++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 3812045..6d7c6ef 100644 --- a/README.md +++ b/README.md @@ -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}); +} +``` \ No newline at end of file diff --git a/demo.zig b/demo.zig index 9765948..c516b98 100644 --- a/demo.zig +++ b/demo.zig @@ -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",