summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/README.md.template4
-rw-r--r--example/comptime-clap.zig9
-rw-r--r--example/simple.zig9
-rw-r--r--example/streaming-clap.zig4
4 files changed, 17 insertions, 9 deletions
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.
14* Supports both passing values using spacing and `=` (`-a 100`, `-a=100`) 14* Supports both passing values using spacing and `=` (`-a 100`, `-a=100`)
15 * Short args also support passing values with no spacing or `=` (`-a100`) 15 * Short args also support passing values with no spacing or `=` (`-a100`)
16 * This all works with chaining (`-ba 100`, `-ba=100`, `-ba100`) 16 * This all works with chaining (`-ba 100`, `-ba=100`, `-ba100`)
17* Supports options that can be specified multiple times (`-e 1 -e 2 -e 3`)
17* Print help message from parameter specification. 18* Print help message from parameter specification.
18* Parse help message to parameter specification. 19* Parse help message to parameter specification.
19 20
@@ -28,7 +29,8 @@ The simplest way to use this library is to just call the `clap.parse` function.
28``` 29```
29 30
30The data structure returned has lookup speed on par with array access (`arr[i]`) and validates 31The data structure returned has lookup speed on par with array access (`arr[i]`) and validates
31that the strings you pass to `option` and `flag` are actually parameters that the program can take: 32that the strings you pass to `option`, `options` and `flag` are actually parameters that the
33program can take:
32 34
33```zig 35```zig
34{} 36{}
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 {
9 // First we specify what parameters our program can take. 9 // First we specify what parameters our program can take.
10 // We can use `parseParam` to parse a string to a `Param(Help)` 10 // We can use `parseParam` to parse a string to a `Param(Help)`
11 const params = comptime [_]clap.Param(clap.Help){ 11 const params = comptime [_]clap.Param(clap.Help){
12 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, 12 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
13 clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, 13 clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable,
14 clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable,
14 clap.Param(clap.Help){ 15 clap.Param(clap.Help){
15 .takes_value = true, 16 .takes_value = .One,
16 }, 17 },
17 }; 18 };
18 19
@@ -29,6 +30,8 @@ pub fn main() !void {
29 debug.warn("--help\n", .{}); 30 debug.warn("--help\n", .{});
30 if (args.option("--number")) |n| 31 if (args.option("--number")) |n|
31 debug.warn("--number = {}\n", .{n}); 32 debug.warn("--number = {}\n", .{n});
33 for (args.options("--string")) |s|
34 debug.warn("--string = {}\n", .{s});
32 for (args.positionals()) |pos| 35 for (args.positionals()) |pos|
33 debug.warn("{}\n", .{pos}); 36 debug.warn("{}\n", .{pos});
34} 37}
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 {
7 // First we specify what parameters our program can take. 7 // First we specify what parameters our program can take.
8 // We can use `parseParam` to parse a string to a `Param(Help)` 8 // We can use `parseParam` to parse a string to a `Param(Help)`
9 const params = comptime [_]clap.Param(clap.Help){ 9 const params = comptime [_]clap.Param(clap.Help){
10 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, 10 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
11 clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, 11 clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable,
12 clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable,
12 clap.Param(clap.Help){ 13 clap.Param(clap.Help){
13 .takes_value = true, 14 .takes_value = .One,
14 }, 15 },
15 }; 16 };
16 17
@@ -21,6 +22,8 @@ pub fn main() !void {
21 debug.warn("--help\n", .{}); 22 debug.warn("--help\n", .{});
22 if (args.option("--number")) |n| 23 if (args.option("--number")) |n|
23 debug.warn("--number = {}\n", .{n}); 24 debug.warn("--number = {}\n", .{n});
25 for (args.options("--string")) |s|
26 debug.warn("--string = {}\n", .{s});
24 for (args.positionals()) |pos| 27 for (args.positionals()) |pos|
25 debug.warn("{}\n", .{pos}); 28 debug.warn("{}\n", .{pos});
26} 29}
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 {
15 clap.Param(u8){ 15 clap.Param(u8){
16 .id = 'n', 16 .id = 'n',
17 .names = clap.Names{ .short = 'n', .long = "number" }, 17 .names = clap.Names{ .short = 'n', .long = "number" },
18 .takes_value = true, 18 .takes_value = .One,
19 }, 19 },
20 clap.Param(u8){ 20 clap.Param(u8){
21 .id = 'f', 21 .id = 'f',
22 .takes_value = true, 22 .takes_value = .One,
23 }, 23 },
24 }; 24 };
25 25