diff options
| author | 2020-11-02 18:04:30 +0000 | |
|---|---|---|
| committer | 2020-11-02 18:04:30 +0000 | |
| commit | 093d29899b8fdf449b944e973b07b5992be2144a (patch) | |
| tree | fb669157fa6e17523b22635c93f920bd4cc57760 /example/simple.zig | |
| parent | adjust examples, README template (diff) | |
| download | zig-clap-093d29899b8fdf449b944e973b07b5992be2144a.tar.gz zig-clap-093d29899b8fdf449b944e973b07b5992be2144a.tar.xz zig-clap-093d29899b8fdf449b944e973b07b5992be2144a.zip | |
Report error context in Diagnostic (#26)
Diffstat (limited to 'example/simple.zig')
| -rw-r--r-- | example/simple.zig | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/example/simple.zig b/example/simple.zig index adea9f9..f7b5953 100644 --- a/example/simple.zig +++ b/example/simple.zig | |||
| @@ -15,7 +15,16 @@ pub fn main() !void { | |||
| 15 | }, | 15 | }, |
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | var args = try clap.parse(clap.Help, ¶ms, std.heap.page_allocator); | 18 | // Initalize our diagnostics, which can be used for reporting useful errors. |
| 19 | // This is optional. You can also just pass `null` to `parser.next` if you | ||
| 20 | // don't care about the extra information `Diagnostics` provides. | ||
| 21 | var diag: clap.Diagnostic = undefined; | ||
| 22 | |||
| 23 | var args = clap.parse(clap.Help, ¶ms, std.heap.page_allocator, &diag) catch |err| { | ||
| 24 | // Report useful error and exit | ||
| 25 | diag.report(std.io.getStdErr().outStream(), err) catch {}; | ||
| 26 | return err; | ||
| 27 | }; | ||
| 19 | defer args.deinit(); | 28 | defer args.deinit(); |
| 20 | 29 | ||
| 21 | if (args.flag("--help")) | 30 | if (args.flag("--help")) |