diff options
| author | 2025-07-22 10:49:49 +0200 | |
|---|---|---|
| committer | 2025-07-22 10:49:49 +0200 | |
| commit | 1c8cc16b660d8933c48b1f8c5321542985c92c04 (patch) | |
| tree | 16260ac3cbc89cadefbb713fc554289032b6ed2c /clap.zig | |
| parent | feat: Add `Diagnostic.reportToFile` (diff) | |
| download | zig-clap-1c8cc16b660d8933c48b1f8c5321542985c92c04.tar.gz zig-clap-1c8cc16b660d8933c48b1f8c5321542985c92c04.tar.xz zig-clap-1c8cc16b660d8933c48b1f8c5321542985c92c04.zip | |
feat: Add `clap.helpToFile`
The code for printing help became quite verbose after writegate. Writing
help to a file like stdout and stderr is very common, so this wrapper
provides a default, buffered way to report to a file.
Diffstat (limited to '')
| -rw-r--r-- | clap.zig | 13 |
1 files changed, 13 insertions, 0 deletions
| @@ -1367,6 +1367,19 @@ pub const HelpOptions = struct { | |||
| 1367 | spacing_between_parameters: usize = 1, | 1367 | spacing_between_parameters: usize = 1, |
| 1368 | }; | 1368 | }; |
| 1369 | 1369 | ||
| 1370 | /// Wrapper around `help`, which writes to a file in a buffered manner | ||
| 1371 | pub fn helpToFile( | ||
| 1372 | file: std.fs.File, | ||
| 1373 | comptime Id: type, | ||
| 1374 | params: []const Param(Id), | ||
| 1375 | opt: HelpOptions, | ||
| 1376 | ) !void { | ||
| 1377 | var buf: [1024]u8 = undefined; | ||
| 1378 | var writer = file.writer(&buf); | ||
| 1379 | try help(&writer.interface, Id, params, opt); | ||
| 1380 | return writer.end(); | ||
| 1381 | } | ||
| 1382 | |||
| 1370 | /// Print a slice of `Param` formatted as a help string to `writer`. This function expects | 1383 | /// Print a slice of `Param` formatted as a help string to `writer`. This function expects |
| 1371 | /// `Id` to have the methods `description` and `value` which are used by `help` to describe | 1384 | /// `Id` to have the methods `description` and `value` which are used by `help` to describe |
| 1372 | /// each parameter. Using `Help` as `Id` is good choice. | 1385 | /// each parameter. Using `Help` as `Id` is good choice. |