From a3d2a261f59983838e3ed5f01d90f18352e6a421 Mon Sep 17 00:00:00 2001 From: Asherah Connor Date: Fri, 28 Aug 2020 17:26:01 +1000 Subject: adjust examples, README template --- example/README.md.template | 4 +++- example/comptime-clap.zig | 9 ++++++--- example/simple.zig | 9 ++++++--- example/streaming-clap.zig | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) (limited to 'example') diff --git a/example/README.md.template b/example/README.md.template index 2afbe86..65b507d 100644 --- a/example/README.md.template +++ b/example/README.md.template @@ -14,6 +14,7 @@ into master on every `zig` release. * Supports both passing values using spacing and `=` (`-a 100`, `-a=100`) * Short args also support passing values with no spacing or `=` (`-a100`) * This all works with chaining (`-ba 100`, `-ba=100`, `-ba100`) +* Supports options that can be specified multiple times (`-e 1 -e 2 -e 3`) * Print help message from parameter specification. * Parse help message to parameter specification. @@ -28,7 +29,8 @@ The simplest way to use this library is to just call the `clap.parse` function. ``` The data structure returned has lookup speed on par with array access (`arr[i]`) and validates -that the strings you pass to `option` and `flag` are actually parameters that the program can take: +that the strings you pass to `option`, `options` and `flag` are actually parameters that the +program can take: ```zig {} diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig index d5c84fe..d709e48 100644 --- a/example/comptime-clap.zig +++ b/example/comptime-clap.zig @@ -9,10 +9,11 @@ pub fn main() !void { // First we specify what parameters our program can take. // We can use `parseParam` to parse a string to a `Param(Help)` const params = comptime [_]clap.Param(clap.Help){ - clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, - clap.parseParam("-n, --number An option parameter, which takes a value.") catch unreachable, + clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, + clap.parseParam("-n, --number An option parameter, which takes a value.") catch unreachable, + clap.parseParam("-s, --string ... An option parameter which can be specified multiple times.") catch unreachable, clap.Param(clap.Help){ - .takes_value = true, + .takes_value = .One, }, }; @@ -29,6 +30,8 @@ pub fn main() !void { debug.warn("--help\n", .{}); if (args.option("--number")) |n| debug.warn("--number = {}\n", .{n}); + for (args.options("--string")) |s| + debug.warn("--string = {}\n", .{s}); for (args.positionals()) |pos| debug.warn("{}\n", .{pos}); } diff --git a/example/simple.zig b/example/simple.zig index 3510317..adea9f9 100644 --- a/example/simple.zig +++ b/example/simple.zig @@ -7,10 +7,11 @@ pub fn main() !void { // First we specify what parameters our program can take. // We can use `parseParam` to parse a string to a `Param(Help)` const params = comptime [_]clap.Param(clap.Help){ - clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, - clap.parseParam("-n, --number An option parameter, which takes a value.") catch unreachable, + clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, + clap.parseParam("-n, --number An option parameter, which takes a value.") catch unreachable, + clap.parseParam("-s, --string ... An option parameter which can be specified multiple times.") catch unreachable, clap.Param(clap.Help){ - .takes_value = true, + .takes_value = .One, }, }; @@ -21,6 +22,8 @@ pub fn main() !void { debug.warn("--help\n", .{}); if (args.option("--number")) |n| debug.warn("--number = {}\n", .{n}); + for (args.options("--string")) |s| + debug.warn("--string = {}\n", .{s}); for (args.positionals()) |pos| debug.warn("{}\n", .{pos}); } diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index faf388a..b92a9e6 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig @@ -15,11 +15,11 @@ pub fn main() !void { clap.Param(u8){ .id = 'n', .names = clap.Names{ .short = 'n', .long = "number" }, - .takes_value = true, + .takes_value = .One, }, clap.Param(u8){ .id = 'f', - .takes_value = true, + .takes_value = .One, }, }; -- cgit v1.2.3