From a305e818bd986c599fff17141617bc4f890276cf Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Wed, 27 Nov 2019 23:13:31 +0900 Subject: Add clap.parse as the simplest way of using the lib --- example/simple-error.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 example/simple-error.zig (limited to 'example/simple-error.zig') diff --git a/example/simple-error.zig b/example/simple-error.zig new file mode 100644 index 0000000..fc72a03 --- /dev/null +++ b/example/simple-error.zig @@ -0,0 +1,15 @@ +const std = @import("std"); +const clap = @import("clap"); + +pub fn main() !void { + // First we specify what parameters our program can take. + // We can use `parseParam` to parse a string to a `Param(Help)` + const params = comptime [_]clap.Param(clap.Help){ + clap.parseParam("-h, --help Display this help and exit.") catch unreachable, + }; + + var args = try clap.parse(clap.Help, params, std.heap.direct_allocator); + defer args.deinit(); + + _ = args.flag("--helps"); +} -- cgit v1.2.3