diff options
| author | 2019-08-17 15:21:45 +0200 | |
|---|---|---|
| committer | 2019-08-17 15:21:45 +0200 | |
| commit | 7399ee309e960733c3f6701eba685fbe284365cf (patch) | |
| tree | cb061d7d326a2a5385ecec2dc5bd0d11fa7a4d34 /example/comptime-clap.zig | |
| parent | build with latest version of zig (diff) | |
| download | zig-clap-7399ee309e960733c3f6701eba685fbe284365cf.tar.gz zig-clap-7399ee309e960733c3f6701eba685fbe284365cf.tar.xz zig-clap-7399ee309e960733c3f6701eba685fbe284365cf.zip | |
adds parseParam
a less verbose way of getting a Param(Help).
Diffstat (limited to '')
| -rw-r--r-- | example/comptime-clap.zig | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig index 0b6d2c4..f73da69 100644 --- a/example/comptime-clap.zig +++ b/example/comptime-clap.zig | |||
| @@ -7,18 +7,11 @@ pub fn main() !void { | |||
| 7 | const allocator = std.heap.direct_allocator; | 7 | const allocator = std.heap.direct_allocator; |
| 8 | 8 | ||
| 9 | // First we specify what parameters our program can take. | 9 | // First we specify what parameters our program can take. |
| 10 | const params = [_]clap.Param([]const u8){ | 10 | // We can use `parseParam` parse a string to a `Param(Help)` |
| 11 | clap.Param([]const u8){ | 11 | const params = comptime [_]clap.Param(clap.Help){ |
| 12 | .id = "Display this help and exit.", | 12 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 13 | .names = clap.Names{ .short = 'h', .long = "help" }, | 13 | clap.parseParam("-n, --number=NUM An option parameter, which takes a value.") catch unreachable, |
| 14 | }, | 14 | clap.Param(clap.Help){ |
| 15 | clap.Param([]const u8){ | ||
| 16 | .id = "An option parameter, which takes a value.", | ||
| 17 | .names = clap.Names{ .short = 'n', .long = "number" }, | ||
| 18 | .takes_value = true, | ||
| 19 | }, | ||
| 20 | clap.Param([]const u8){ | ||
| 21 | .id = "", | ||
| 22 | .takes_value = true, | 15 | .takes_value = true, |
| 23 | }, | 16 | }, |
| 24 | }; | 17 | }; |
| @@ -32,7 +25,7 @@ pub fn main() !void { | |||
| 32 | const exe = try iter.next(); | 25 | const exe = try iter.next(); |
| 33 | 26 | ||
| 34 | // Finally we can parse the arguments | 27 | // Finally we can parse the arguments |
| 35 | var args = try clap.ComptimeClap([]const u8, params).parse(allocator, clap.args.OsIterator, &iter); | 28 | var args = try clap.ComptimeClap(clap.Help, params).parse(allocator, clap.args.OsIterator, &iter); |
| 36 | defer args.deinit(); | 29 | defer args.deinit(); |
| 37 | 30 | ||
| 38 | if (args.flag("--help")) | 31 | if (args.flag("--help")) |