From 7f9eabeecfde0d909ab50a8fb10ad3fedff93d03 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Mon, 25 Jul 2022 18:15:45 +0200 Subject: Add clap.parsers.enumeration for parsing enums closes #78 --- example/simple-ex.zig | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'example') diff --git a/example/simple-ex.zig b/example/simple-ex.zig index d0d214d..fb20d07 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig @@ -11,6 +11,7 @@ pub fn main() !void { const params = comptime clap.parseParamsComptime( \\-h, --help Display this help and exit. \\-n, --number An option parameter, which takes a value. + \\-a, --answer An option parameter which takes an enum. \\-s, --string ... An option parameter which can be specified multiple times. \\... \\ @@ -18,10 +19,12 @@ pub fn main() !void { // Declare our own parsers which are used to map the argument strings to other // types. + const YesNo = enum { yes, no }; const parsers = comptime .{ .STR = clap.parsers.string, .FILE = clap.parsers.string, .INT = clap.parsers.int(usize, 10), + .ANSWER = clap.parsers.enumeration(YesNo), }; var diag = clap.Diagnostic{}; @@ -37,6 +40,8 @@ pub fn main() !void { debug.print("--help\n", .{}); if (res.args.number) |n| debug.print("--number = {}\n", .{n}); + if (res.args.answer) |a| + debug.print("--answer = {s}\n", .{@tagName(a)}); for (res.args.string) |s| debug.print("--string = {s}\n", .{s}); for (res.positionals) |pos| -- cgit v1.2.3