diff options
Diffstat (limited to 'example/comptime-clap.zig')
| -rw-r--r-- | example/comptime-clap.zig | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig index d709e48..530c7e6 100644 --- a/example/comptime-clap.zig +++ b/example/comptime-clap.zig | |||
| @@ -16,14 +16,24 @@ pub fn main() !void { | |||
| 16 | .takes_value = .One, | 16 | .takes_value = .One, |
| 17 | }, | 17 | }, |
| 18 | }; | 18 | }; |
| 19 | const Clap = clap.ComptimeClap(clap.Help, clap.args.OsIterator, ¶ms); | ||
| 19 | 20 | ||
| 20 | // We then initialize an argument iterator. We will use the OsIterator as it nicely | 21 | // We then initialize an argument iterator. We will use the OsIterator as it nicely |
| 21 | // wraps iterating over arguments the most efficient way on each os. | 22 | // wraps iterating over arguments the most efficient way on each os. |
| 22 | var iter = try clap.args.OsIterator.init(allocator); | 23 | var iter = try clap.args.OsIterator.init(allocator); |
| 23 | defer iter.deinit(); | 24 | defer iter.deinit(); |
| 24 | 25 | ||
| 26 | // Initalize our diagnostics, which can be used for reporting useful errors. | ||
| 27 | // This is optional. You can also just pass `null` to `parser.next` if you | ||
| 28 | // don't care about the extra information `Diagnostics` provides. | ||
| 29 | var diag: clap.Diagnostic = undefined; | ||
| 30 | |||
| 25 | // Parse the arguments | 31 | // Parse the arguments |
| 26 | var args = try clap.ComptimeClap(clap.Help, ¶ms).parse(allocator, clap.args.OsIterator, &iter); | 32 | var args = Clap.parse(allocator, &iter, &diag) catch |err| { |
| 33 | // Report useful error and exit | ||
| 34 | diag.report(std.io.getStdErr().outStream(), err) catch {}; | ||
| 35 | return err; | ||
| 36 | }; | ||
| 27 | defer args.deinit(); | 37 | defer args.deinit(); |
| 28 | 38 | ||
| 29 | if (args.flag("--help")) | 39 | if (args.flag("--help")) |