diff options
| author | 2022-07-25 18:15:45 +0200 | |
|---|---|---|
| committer | 2022-07-25 18:16:19 +0200 | |
| commit | 7f9eabeecfde0d909ab50a8fb10ad3fedff93d03 (patch) | |
| tree | 0e7ee4f043ef215524ec41062e2442cd00615270 /README.md | |
| parent | Update LICENSE (diff) | |
| download | zig-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 'README.md')
| -rw-r--r-- | README.md | 5 |
1 files changed, 5 insertions, 0 deletions
| @@ -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| |