diff options
Diffstat (limited to '')
| -rw-r--r-- | README.md | 48 |
1 files changed, 24 insertions, 24 deletions
| @@ -34,30 +34,30 @@ pub fn main() !void { | |||
| 34 | // First we specify what parameters our program can take. | 34 | // First we specify what parameters our program can take. |
| 35 | // 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)` |
| 36 | const params = comptime [_]clap.Param(clap.Help){ | 36 | const params = comptime [_]clap.Param(clap.Help){ |
| 37 | clap.untyped.parseParam("-h, --help Display this help and exit.") catch unreachable, | 37 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 38 | clap.untyped.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.untyped.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, | 39 | clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, |
| 40 | clap.untyped.parseParam("<POS>...") catch unreachable, | 40 | clap.parseParam("<POS>...") catch unreachable, |
| 41 | }; | 41 | }; |
| 42 | 42 | ||
| 43 | // Initalize our diagnostics, which can be used for reporting useful errors. | 43 | // Initalize our diagnostics, which can be used for reporting useful errors. |
| 44 | // This is optional. You can also pass `.{}` to `clap.parse` if you don't | 44 | // This is optional. You can also pass `.{}` to `clap.parse` if you don't |
| 45 | // care about the extra information `Diagnostics` provides. | 45 | // care about the extra information `Diagnostics` provides. |
| 46 | var diag = clap.Diagnostic{}; | 46 | var diag = clap.Diagnostic{}; |
| 47 | var res = clap.untyped.parse(clap.Help, ¶ms, .{ .diagnostic = &diag }) catch |err| { | 47 | var args = clap.parse(clap.Help, ¶ms, .{ .diagnostic = &diag }) catch |err| { |
| 48 | // Report useful error and exit | 48 | // Report useful error and exit |
| 49 | diag.report(io.getStdErr().writer(), err) catch {}; | 49 | diag.report(io.getStdErr().writer(), err) catch {}; |
| 50 | return err; | 50 | return err; |
| 51 | }; | 51 | }; |
| 52 | defer res.deinit(); | 52 | defer args.deinit(); |
| 53 | 53 | ||
| 54 | if (res.args.help) | 54 | if (args.flag("--help")) |
| 55 | debug.print("--help\n", .{}); | 55 | debug.print("--help\n", .{}); |
| 56 | if (res.args.number) |n| | 56 | if (args.option("--number")) |n| |
| 57 | debug.print("--number = {s}\n", .{n}); | 57 | debug.print("--number = {s}\n", .{n}); |
| 58 | for (res.args.string) |s| | 58 | for (args.options("--string")) |s| |
| 59 | debug.print("--string = {s}\n", .{s}); | 59 | debug.print("--string = {s}\n", .{s}); |
| 60 | for (res.positionals) |pos| | 60 | for (args.positionals()) |pos| |
| 61 | debug.print("{s}\n", .{pos}); | 61 | debug.print("{s}\n", .{pos}); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -100,9 +100,9 @@ zig-clap/example/simple-error.zig:16:18: note: called from here | |||
| 100 | 100 | ||
| 101 | There is also a `parseEx` variant that takes an argument iterator. | 101 | There is also a `parseEx` variant that takes an argument iterator. |
| 102 | 102 | ||
| 103 | ### `streaming.Clap` | 103 | ### `StreamingClap` |
| 104 | 104 | ||
| 105 | The `streaming.Clap` is the base of all the other parsers. It's a streaming parser that uses an | 105 | The `StreamingClap` is the base of all the other parsers. It's a streaming parser that uses an |
| 106 | `args.Iterator` to provide it with arguments lazily. | 106 | `args.Iterator` to provide it with arguments lazily. |
| 107 | 107 | ||
| 108 | ```zig | 108 | ```zig |
| @@ -140,7 +140,7 @@ pub fn main() !void { | |||
| 140 | // This is optional. You can also leave the `diagnostic` field unset if you | 140 | // This is optional. You can also leave the `diagnostic` field unset if you |
| 141 | // don't care about the extra information `Diagnostic` provides. | 141 | // don't care about the extra information `Diagnostic` provides. |
| 142 | var diag = clap.Diagnostic{}; | 142 | var diag = clap.Diagnostic{}; |
| 143 | var parser = clap.streaming.Clap(u8, process.ArgIterator){ | 143 | var parser = clap.StreamingClap(u8, process.ArgIterator){ |
| 144 | .params = ¶ms, | 144 | .params = ¶ms, |
| 145 | .iter = &iter, | 145 | .iter = &iter, |
| 146 | .diagnostic = &diag, | 146 | .diagnostic = &diag, |
| @@ -182,17 +182,17 @@ const std = @import("std"); | |||
| 182 | 182 | ||
| 183 | pub fn main() !void { | 183 | pub fn main() !void { |
| 184 | const params = comptime [_]clap.Param(clap.Help){ | 184 | const params = comptime [_]clap.Param(clap.Help){ |
| 185 | clap.untyped.parseParam("-h, --help Display this help and exit. ") catch unreachable, | 185 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 186 | clap.untyped.parseParam("-v, --version Output version information and exit.") catch unreachable, | 186 | clap.parseParam("-v, --version Output version information and exit.") catch unreachable, |
| 187 | }; | 187 | }; |
| 188 | 188 | ||
| 189 | var res = try clap.untyped.parse(clap.Help, ¶ms, .{}); | 189 | var args = try clap.parse(clap.Help, ¶ms, .{}); |
| 190 | defer res.deinit(); | 190 | defer args.deinit(); |
| 191 | 191 | ||
| 192 | // clap.help is a function that can print a simple help message, given a | 192 | // clap.help is a function that can print a simple help message, given a |
| 193 | // slice of Param(Help). There is also a helpEx, which can print a | 193 | // slice of Param(Help). There is also a helpEx, which can print a |
| 194 | // help message for any Param, but it is more verbose to call. | 194 | // help message for any Param, but it is more verbose to call. |
| 195 | if (res.args.help) | 195 | if (args.flag("--help")) |
| 196 | return clap.help(std.io.getStdErr().writer(), ¶ms); | 196 | return clap.help(std.io.getStdErr().writer(), ¶ms); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| @@ -224,18 +224,18 @@ const std = @import("std"); | |||
| 224 | 224 | ||
| 225 | pub fn main() !void { | 225 | pub fn main() !void { |
| 226 | const params = comptime [_]clap.Param(clap.Help){ | 226 | const params = comptime [_]clap.Param(clap.Help){ |
| 227 | clap.untyped.parseParam("-h, --help Display this help and exit.") catch unreachable, | 227 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 228 | clap.untyped.parseParam("-v, --version Output version information and exit.") catch unreachable, | 228 | clap.parseParam("-v, --version Output version information and exit. ") catch unreachable, |
| 229 | clap.untyped.parseParam(" --value <N> An option parameter, which takes a value.") catch unreachable, | 229 | clap.parseParam(" --value <N> An option parameter, which takes a value.") catch unreachable, |
| 230 | }; | 230 | }; |
| 231 | 231 | ||
| 232 | var res = try clap.untyped.parse(clap.Help, ¶ms, .{}); | 232 | var args = try clap.parse(clap.Help, ¶ms, .{}); |
| 233 | defer res.deinit(); | 233 | defer args.deinit(); |
| 234 | 234 | ||
| 235 | // clap.usage is a function that can print a simple usage message, given a | 235 | // clap.usage is a function that can print a simple usage message, given a |
| 236 | // slice of Param(Help). There is also a usageEx, which can print a | 236 | // slice of Param(Help). There is also a usageEx, which can print a |
| 237 | // usage message for any Param, but it is more verbose to call. | 237 | // usage message for any Param, but it is more verbose to call. |
| 238 | if (res.args.help) | 238 | if (args.flag("--help")) |
| 239 | return clap.usage(std.io.getStdErr().writer(), ¶ms); | 239 | return clap.usage(std.io.getStdErr().writer(), ¶ms); |
| 240 | } | 240 | } |
| 241 | 241 | ||