summaryrefslogtreecommitdiff
path: root/example/streaming-clap.zig
diff options
context:
space:
mode:
authorGravatar Komari Spaghetti2020-11-02 18:04:30 +0000
committerGravatar Jimmi Holst Christensen2020-11-02 19:05:41 +0100
commit42894f6c8b957541ac0b1830139312047cd8fdc6 (patch)
treef5c6c839334b863f77e665879be0d467614543f2 /example/streaming-clap.zig
parentuse null sentinel in OsIterator (#27) (diff)
downloadzig-clap-42894f6c8b957541ac0b1830139312047cd8fdc6.tar.gz
zig-clap-42894f6c8b957541ac0b1830139312047cd8fdc6.tar.xz
zig-clap-42894f6c8b957541ac0b1830139312047cd8fdc6.zip
Report error context in Diagnostic (#26)
Diffstat (limited to 'example/streaming-clap.zig')
-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", .{}),