summaryrefslogtreecommitdiff
path: root/example/simple-ex.zig
diff options
context:
space:
mode:
Diffstat (limited to 'example/simple-ex.zig')
-rw-r--r--example/simple-ex.zig5
1 files changed, 5 insertions, 0 deletions
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 {
11 const params = comptime clap.parseParamsComptime( 11 const params = comptime clap.parseParamsComptime(
12 \\-h, --help Display this help and exit. 12 \\-h, --help Display this help and exit.
13 \\-n, --number <INT> An option parameter, which takes a value. 13 \\-n, --number <INT> An option parameter, which takes a value.
14 \\-a, --answer <ANSWER> An option parameter which takes an enum.
14 \\-s, --string <STR>... An option parameter which can be specified multiple times. 15 \\-s, --string <STR>... An option parameter which can be specified multiple times.
15 \\<FILE>... 16 \\<FILE>...
16 \\ 17 \\
@@ -18,10 +19,12 @@ pub fn main() !void {
18 19
19 // Declare our own parsers which are used to map the argument strings to other 20 // Declare our own parsers which are used to map the argument strings to other
20 // types. 21 // types.
22 const YesNo = enum { yes, no };
21 const parsers = comptime .{ 23 const parsers = comptime .{
22 .STR = clap.parsers.string, 24 .STR = clap.parsers.string,
23 .FILE = clap.parsers.string, 25 .FILE = clap.parsers.string,
24 .INT = clap.parsers.int(usize, 10), 26 .INT = clap.parsers.int(usize, 10),
27 .ANSWER = clap.parsers.enumeration(YesNo),
25 }; 28 };
26 29
27 var diag = clap.Diagnostic{}; 30 var diag = clap.Diagnostic{};
@@ -37,6 +40,8 @@ pub fn main() !void {
37 debug.print("--help\n", .{}); 40 debug.print("--help\n", .{});
38 if (res.args.number) |n| 41 if (res.args.number) |n|
39 debug.print("--number = {}\n", .{n}); 42 debug.print("--number = {}\n", .{n});
43 if (res.args.answer) |a|
44 debug.print("--answer = {s}\n", .{@tagName(a)});
40 for (res.args.string) |s| 45 for (res.args.string) |s|
41 debug.print("--string = {s}\n", .{s}); 46 debug.print("--string = {s}\n", .{s});
42 for (res.positionals) |pos| 47 for (res.positionals) |pos|