From 1c8cc16b660d8933c48b1f8c5321542985c92c04 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Tue, 22 Jul 2025 10:49:49 +0200 Subject: 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. --- example/help.zig | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'example/help.zig') diff --git a/example/help.zig b/example/help.zig index 676a56a..5c88d83 100644 --- a/example/help.zig +++ b/example/help.zig @@ -17,12 +17,8 @@ pub fn main() !void { // where `Id` has a `description` and `value` method (`Param(Help)` is one such parameter). // The last argument contains options as to how `help` should print those parameters. Using // `.{}` means the default options. - if (res.args.help != 0) { - var buf: [1024]u8 = undefined; - var stderr = std.fs.File.stderr().writer(&buf); - try clap.help(&stderr.interface, clap.Help, ¶ms, .{}); - return stderr.interface.flush(); - } + if (res.args.help != 0) + return clap.helpToFile(.stderr(), clap.Help, ¶ms, .{}); } const clap = @import("clap"); -- cgit v1.2.3