From 42894f6c8b957541ac0b1830139312047cd8fdc6 Mon Sep 17 00:00:00 2001 From: Komari Spaghetti Date: Mon, 2 Nov 2020 18:04:30 +0000 Subject: Report error context in Diagnostic (#26) --- example/simple.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'example/simple.zig') 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 { }, }; - var args = try clap.parse(clap.Help, ¶ms, std.heap.page_allocator); + // Initalize our diagnostics, which can be used for reporting useful errors. + // This is optional. You can also just pass `null` to `parser.next` if you + // don't care about the extra information `Diagnostics` provides. + var diag: clap.Diagnostic = undefined; + + var args = clap.parse(clap.Help, ¶ms, std.heap.page_allocator, &diag) catch |err| { + // Report useful error and exit + diag.report(std.io.getStdErr().outStream(), err) catch {}; + return err; + }; defer args.deinit(); if (args.flag("--help")) -- cgit v1.2.3