summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2022-07-25 18:15:45 +0200
committerGravatar Jimmi Holst Christensen2022-07-25 18:16:19 +0200
commit7f9eabeecfde0d909ab50a8fb10ad3fedff93d03 (patch)
tree0e7ee4f043ef215524ec41062e2442cd00615270 /README.md
parentUpdate LICENSE (diff)
downloadzig-clap-7f9eabeecfde0d909ab50a8fb10ad3fedff93d03.tar.gz
zig-clap-7f9eabeecfde0d909ab50a8fb10ad3fedff93d03.tar.xz
zig-clap-7f9eabeecfde0d909ab50a8fb10ad3fedff93d03.zip
Add clap.parsers.enumeration for parsing enums
closes #78
Diffstat (limited to '')
-rw-r--r--README.md5
1 files changed, 5 insertions, 0 deletions
diff --git a/README.md b/README.md
index 8457118..d37a222 100644
--- a/README.md
+++ b/README.md
@@ -96,6 +96,7 @@ pub fn main() !void {
96 const params = comptime clap.parseParamsComptime( 96 const params = comptime clap.parseParamsComptime(
97 \\-h, --help Display this help and exit. 97 \\-h, --help Display this help and exit.
98 \\-n, --number <INT> An option parameter, which takes a value. 98 \\-n, --number <INT> An option parameter, which takes a value.
99 \\-a, --answer <ANSWER> An option parameter which takes an enum.
99 \\-s, --string <STR>... An option parameter which can be specified multiple times. 100 \\-s, --string <STR>... An option parameter which can be specified multiple times.
100 \\<FILE>... 101 \\<FILE>...
101 \\ 102 \\
@@ -103,10 +104,12 @@ pub fn main() !void {
103 104
104 // Declare our own parsers which are used to map the argument strings to other 105 // Declare our own parsers which are used to map the argument strings to other
105 // types. 106 // types.
107 const YesNo = enum { yes, no };
106 const parsers = comptime .{ 108 const parsers = comptime .{
107 .STR = clap.parsers.string, 109 .STR = clap.parsers.string,
108 .FILE = clap.parsers.string, 110 .FILE = clap.parsers.string,
109 .INT = clap.parsers.int(usize, 10), 111 .INT = clap.parsers.int(usize, 10),
112 .ANSWER = clap.parsers.enumeration(YesNo),
110 }; 113 };
111 114
112 var diag = clap.Diagnostic{}; 115 var diag = clap.Diagnostic{};
@@ -122,6 +125,8 @@ pub fn main() !void {
122 debug.print("--help\n", .{}); 125 debug.print("--help\n", .{});
123 if (res.args.number) |n| 126 if (res.args.number) |n|
124 debug.print("--number = {}\n", .{n}); 127 debug.print("--number = {}\n", .{n});
128 if (res.args.answer) |a|
129 debug.print("--answer = {s}\n", .{@tagName(a)});
125 for (res.args.string) |s| 130 for (res.args.string) |s|
126 debug.print("--string = {s}\n", .{s}); 131 debug.print("--string = {s}\n", .{s});
127 for (res.positionals) |pos| 132 for (res.positionals) |pos|