summaryrefslogtreecommitdiff
path: root/example/streaming-clap.zig
diff options
context:
space:
mode:
authorGravatar Komari Spaghetti2020-11-02 18:04:30 +0000
committerGravatar GitHub2020-11-02 18:04:30 +0000
commit093d29899b8fdf449b944e973b07b5992be2144a (patch)
treefb669157fa6e17523b22635c93f920bd4cc57760 /example/streaming-clap.zig
parentadjust examples, README template (diff)
downloadzig-clap-093d29899b8fdf449b944e973b07b5992be2144a.tar.gz
zig-clap-093d29899b8fdf449b944e973b07b5992be2144a.tar.xz
zig-clap-093d29899b8fdf449b944e973b07b5992be2144a.zip
Report error context in Diagnostic (#26)
Diffstat (limited to '')
-rw-r--r--example/streaming-clap.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig
index b92a9e6..941070f 100644
--- a/example/streaming-clap.zig
+++ b/example/streaming-clap.zig
@@ -34,8 +34,17 @@ pub fn main() !void {
34 .iter = &iter, 34 .iter = &iter,
35 }; 35 };
36 36
37 // Initalize our diagnostics, which can be used for reporting useful errors.
38 // This is optional. You can also just pass `null` to `parser.next` if you
39 // don't care about the extra information `Diagnostics` provides.
40 var diag: clap.Diagnostic = undefined;
41
37 // Because we use a streaming parser, we have to consume each argument parsed individually. 42 // Because we use a streaming parser, we have to consume each argument parsed individually.
38 while (try parser.next()) |arg| { 43 while (parser.next(&diag) catch |err| {
44 // Report useful error and exit
45 diag.report(std.io.getStdErr().outStream(), err) catch {};
46 return err;
47 }) |arg| {
39 // arg.param will point to the parameter which matched the argument. 48 // arg.param will point to the parameter which matched the argument.
40 switch (arg.param.id) { 49 switch (arg.param.id) {
41 'h' => debug.warn("Help!\n", .{}), 50 'h' => debug.warn("Help!\n", .{}),