diff options
Diffstat (limited to '')
| -rw-r--r-- | README.md | 26 | ||||
| -rw-r--r-- | clap/comptime.zig | 6 | ||||
| -rw-r--r-- | example/README.md.template | 4 | ||||
| -rw-r--r-- | example/comptime-clap.zig | 9 | ||||
| -rw-r--r-- | example/simple.zig | 9 | ||||
| -rw-r--r-- | example/streaming-clap.zig | 4 |
6 files changed, 37 insertions, 21 deletions
| @@ -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 | ||
| @@ -33,10 +34,11 @@ pub fn main() !void { | |||
| 33 | // First we specify what parameters our program can take. | 34 | // First we specify what parameters our program can take. |
| 34 | // We can use `parseParam` to parse a string to a `Param(Help)` | 35 | // We can use `parseParam` to parse a string to a `Param(Help)` |
| 35 | const params = comptime [_]clap.Param(clap.Help){ | 36 | const params = comptime [_]clap.Param(clap.Help){ |
| 36 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, | 37 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 37 | clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, | 38 | clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, |
| 39 | clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, | ||
| 38 | clap.Param(clap.Help){ | 40 | clap.Param(clap.Help){ |
| 39 | .takes_value = true, | 41 | .takes_value = .One, |
| 40 | }, | 42 | }, |
| 41 | }; | 43 | }; |
| 42 | 44 | ||
| @@ -47,6 +49,8 @@ pub fn main() !void { | |||
| 47 | debug.warn("--help\n", .{}); | 49 | debug.warn("--help\n", .{}); |
| 48 | if (args.option("--number")) |n| | 50 | if (args.option("--number")) |n| |
| 49 | debug.warn("--number = {}\n", .{n}); | 51 | debug.warn("--number = {}\n", .{n}); |
| 52 | for (args.options("--string")) |s| | ||
| 53 | debug.warn("--string = {}\n", .{s}); | ||
| 50 | for (args.positionals()) |pos| | 54 | for (args.positionals()) |pos| |
| 51 | debug.warn("{}\n", .{pos}); | 55 | debug.warn("{}\n", .{pos}); |
| 52 | } | 56 | } |
| @@ -54,7 +58,8 @@ pub fn main() !void { | |||
| 54 | ``` | 58 | ``` |
| 55 | 59 | ||
| 56 | The data structure returned has lookup speed on par with array access (`arr[i]`) and validates | 60 | The data structure returned has lookup speed on par with array access (`arr[i]`) and validates |
| 57 | that the strings you pass to `option` and `flag` are actually parameters that the program can take: | 61 | that the strings you pass to `option`, `options` and `flag` are actually parameters that the |
| 62 | program can take: | ||
| 58 | 63 | ||
| 59 | ```zig | 64 | ```zig |
| 60 | const std = @import("std"); | 65 | const std = @import("std"); |
| @@ -106,10 +111,11 @@ pub fn main() !void { | |||
| 106 | // First we specify what parameters our program can take. | 111 | // First we specify what parameters our program can take. |
| 107 | // We can use `parseParam` to parse a string to a `Param(Help)` | 112 | // We can use `parseParam` to parse a string to a `Param(Help)` |
| 108 | const params = comptime [_]clap.Param(clap.Help){ | 113 | const params = comptime [_]clap.Param(clap.Help){ |
| 109 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, | 114 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 110 | clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, | 115 | clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, |
| 116 | clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, | ||
| 111 | clap.Param(clap.Help){ | 117 | clap.Param(clap.Help){ |
| 112 | .takes_value = true, | 118 | .takes_value = .One, |
| 113 | }, | 119 | }, |
| 114 | }; | 120 | }; |
| 115 | 121 | ||
| @@ -126,6 +132,8 @@ pub fn main() !void { | |||
| 126 | debug.warn("--help\n", .{}); | 132 | debug.warn("--help\n", .{}); |
| 127 | if (args.option("--number")) |n| | 133 | if (args.option("--number")) |n| |
| 128 | debug.warn("--number = {}\n", .{n}); | 134 | debug.warn("--number = {}\n", .{n}); |
| 135 | for (args.options("--string")) |s| | ||
| 136 | debug.warn("--string = {}\n", .{s}); | ||
| 129 | for (args.positionals()) |pos| | 137 | for (args.positionals()) |pos| |
| 130 | debug.warn("{}\n", .{pos}); | 138 | debug.warn("{}\n", .{pos}); |
| 131 | } | 139 | } |
| @@ -155,11 +163,11 @@ pub fn main() !void { | |||
| 155 | clap.Param(u8){ | 163 | clap.Param(u8){ |
| 156 | .id = 'n', | 164 | .id = 'n', |
| 157 | .names = clap.Names{ .short = 'n', .long = "number" }, | 165 | .names = clap.Names{ .short = 'n', .long = "number" }, |
| 158 | .takes_value = true, | 166 | .takes_value = .One, |
| 159 | }, | 167 | }, |
| 160 | clap.Param(u8){ | 168 | clap.Param(u8){ |
| 161 | .id = 'f', | 169 | .id = 'f', |
| 162 | .takes_value = true, | 170 | .takes_value = .One, |
| 163 | }, | 171 | }, |
| 164 | }; | 172 | }; |
| 165 | 173 | ||
diff --git a/clap/comptime.zig b/clap/comptime.zig index b0edb2a..28ec42b 100644 --- a/clap/comptime.zig +++ b/clap/comptime.zig | |||
| @@ -167,10 +167,10 @@ test "clap.comptime.ComptimeClap" { | |||
| 167 | testing.expect(args.flag("--aa")); | 167 | testing.expect(args.flag("--aa")); |
| 168 | testing.expect(!args.flag("-b")); | 168 | testing.expect(!args.flag("-b")); |
| 169 | testing.expect(!args.flag("--bb")); | 169 | testing.expect(!args.flag("--bb")); |
| 170 | testing.expectEqualStrings("0", args.option("-c").?); | 170 | testing.expectEqualSlices(u8, "0", args.option("-c").?); |
| 171 | testing.expectEqualStrings("0", args.option("--cc").?); | 171 | testing.expectEqualSlices(u8, "0", args.option("--cc").?); |
| 172 | testing.expectEqual(@as(usize, 1), args.positionals().len); | 172 | testing.expectEqual(@as(usize, 1), args.positionals().len); |
| 173 | testing.expectEqualStrings("something", args.positionals()[0]); | 173 | testing.expectEqualSlices(u8, "something", args.positionals()[0]); |
| 174 | testing.expectEqualSlices([]const u8, &[_][]const u8{ "a", "b" }, args.options("-d")); | 174 | testing.expectEqualSlices([]const u8, &[_][]const u8{ "a", "b" }, args.options("-d")); |
| 175 | testing.expectEqualSlices([]const u8, &[_][]const u8{ "a", "b" }, args.options("--dd")); | 175 | testing.expectEqualSlices([]const u8, &[_][]const u8{ "a", "b" }, args.options("--dd")); |
| 176 | } | 176 | } |
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 | ||
| 30 | The data structure returned has lookup speed on par with array access (`arr[i]`) and validates | 31 | The data structure returned has lookup speed on par with array access (`arr[i]`) and validates |
| 31 | that the strings you pass to `option` and `flag` are actually parameters that the program can take: | 32 | that the strings you pass to `option`, `options` and `flag` are actually parameters that the |
| 33 | program 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 | ||