summaryrefslogtreecommitdiff
path: root/example/simple-ex.zig
diff options
context:
space:
mode:
authorGravatar Komari Spaghetti2021-04-26 16:23:15 +0200
committerGravatar Komari Spaghetti2021-04-28 16:59:30 +0200
commitaa334d8c1df252f48960e0253eb25544678a6023 (patch)
tree34f23f4ac4ff10a059cff74b0e7409a4c13d2ebe /example/simple-ex.zig
parentAdd gyro.zzz (diff)
downloadzig-clap-aa334d8c1df252f48960e0253eb25544678a6023.tar.gz
zig-clap-aa334d8c1df252f48960e0253eb25544678a6023.tar.xz
zig-clap-aa334d8c1df252f48960e0253eb25544678a6023.zip
Refactor Diagnostic (and others) into a ParseOption struct
This allows for default arguments, which we can also extend without breaking peoples code in the future. This is a breaking change right now though.
Diffstat (limited to 'example/simple-ex.zig')
-rw-r--r--example/simple-ex.zig14
1 files changed, 8 insertions, 6 deletions
diff --git a/example/simple-ex.zig b/example/simple-ex.zig
index d6ecc44..f504d63 100644
--- a/example/simple-ex.zig
+++ b/example/simple-ex.zig
@@ -1,5 +1,5 @@
1const std = @import("std");
2const clap = @import("clap"); 1const clap = @import("clap");
2const std = @import("std");
3 3
4const debug = std.debug; 4const debug = std.debug;
5 5
@@ -21,11 +21,13 @@ pub fn main() !void {
21 defer iter.deinit(); 21 defer iter.deinit();
22 22
23 // Initalize our diagnostics, which can be used for reporting useful errors. 23 // Initalize our diagnostics, which can be used for reporting useful errors.
24 // This is optional. You can also just pass `null` to `parser.next` if you 24 // This is optional. You can also pass `.{}` to `clap.parse` if you don't
25 // don't care about the extra information `Diagnostics` provides. 25 // care about the extra information `Diagnostics` provides.
26 var diag: clap.Diagnostic = undefined; 26 var diag = clap.Diagnostic{};
27 27 var args = clap.parseEx(clap.Help, &params, &iter, .{
28 var args = clap.parseEx(clap.Help, &params, allocator, &iter, &diag) catch |err| { 28 .allocator = allocator,
29 .diagnostic = &diag,
30 }) catch |err| {
29 // Report useful error and exit 31 // Report useful error and exit
30 diag.report(std.io.getStdErr().outStream(), err) catch {}; 32 diag.report(std.io.getStdErr().outStream(), err) catch {};
31 return err; 33 return err;