From 0356f53d5bc46011efc6b6ffbfe0b202466d7b4f Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Tue, 22 Jul 2025 10:54:19 +0200 Subject: feat: Add `clap.usageToFile` The code for printing usage became quite verbose after writegate. Writing usage to a file like stdout and stderr is very common, so this wrapper provides a default, buffered way to report to a file. --- example/usage.zig | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'example/usage.zig') diff --git a/example/usage.zig b/example/usage.zig index 8bd25b7..b7308f5 100644 --- a/example/usage.zig +++ b/example/usage.zig @@ -14,15 +14,10 @@ pub fn main() !void { }); defer res.deinit(); - // `clap.usage` is a function that can print a simple help message. It can print any `Param` - // where `Id` has a `value` method (`Param(Help)` is one such parameter). - if (res.args.help != 0) { - var buf: [1024]u8 = undefined; - var stderr = std.fs.File.stderr().writer(&buf); - clap.usage(&stderr.interface, clap.Help, ¶ms) catch {}; - try stderr.interface.flush(); - return; - } + // `clap.usageToFile` is a function that can print a simple usage string. It can print any + // `Param` where `Id` has a `value` method (`Param(Help)` is one such parameter). + if (res.args.help != 0) + return clap.usageToFile(.stdout(), clap.Help, ¶ms); } const clap = @import("clap"); -- cgit v1.2.3