diff options
| author | 2025-07-22 10:44:11 +0200 | |
|---|---|---|
| committer | 2025-07-22 10:44:11 +0200 | |
| commit | 095409eb0421f0f970c246b371b39dab2ff912aa (patch) | |
| tree | 08ed3d08575d8a3b2613874a01dc7f98312bf272 /example/streaming-clap.zig | |
| parent | Update to Zig 0.15.0-dev.1147 (diff) | |
| download | zig-clap-095409eb0421f0f970c246b371b39dab2ff912aa.tar.gz zig-clap-095409eb0421f0f970c246b371b39dab2ff912aa.tar.xz zig-clap-095409eb0421f0f970c246b371b39dab2ff912aa.zip | |
feat: Add `Diagnostic.reportToFile`
The code for reporting errors became quite verbose after writegate.
Reporting to stderr is very common, so this wrapper provides a default,
buffered way to report to a file.
Diffstat (limited to '')
| -rw-r--r-- | example/streaming-clap.zig | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index d60167c..4cd6962 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -34,10 +34,8 @@ pub fn main() !void { | |||
| 34 | // Because we use a streaming parser, we have to consume each argument parsed individually. | 34 | // Because we use a streaming parser, we have to consume each argument parsed individually. |
| 35 | while (parser.next() catch |err| { | 35 | while (parser.next() catch |err| { |
| 36 | // Report useful error and exit. | 36 | // Report useful error and exit. |
| 37 | var buf: [1024]u8 = undefined; | 37 | try diag.reportToFile(.stderr(), err); |
| 38 | var stderr = std.fs.File.stderr().writer(&buf); | 38 | return err; |
| 39 | try diag.report(&stderr.interface, err); | ||
| 40 | return stderr.interface.flush(); | ||
| 41 | }) |arg| { | 39 | }) |arg| { |
| 42 | // arg.param will point to the parameter which matched the argument. | 40 | // arg.param will point to the parameter which matched the argument. |
| 43 | switch (arg.param.id) { | 41 | switch (arg.param.id) { |