diff options
| author | 2025-07-22 10:54:19 +0200 | |
|---|---|---|
| committer | 2025-07-22 10:54:19 +0200 | |
| commit | 0356f53d5bc46011efc6b6ffbfe0b202466d7b4f (patch) | |
| tree | 98efe75192b2aca9f293ec0ce03c78f20a6e1ec3 /example/usage.zig | |
| parent | feat: Add `clap.helpToFile` (diff) | |
| download | zig-clap-0356f53d5bc46011efc6b6ffbfe0b202466d7b4f.tar.gz zig-clap-0356f53d5bc46011efc6b6ffbfe0b202466d7b4f.tar.xz zig-clap-0356f53d5bc46011efc6b6ffbfe0b202466d7b4f.zip | |
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.
Diffstat (limited to 'example/usage.zig')
| -rw-r--r-- | example/usage.zig | 13 |
1 files changed, 4 insertions, 9 deletions
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 { | |||
| 14 | }); | 14 | }); |
| 15 | defer res.deinit(); | 15 | defer res.deinit(); |
| 16 | 16 | ||
| 17 | // `clap.usage` is a function that can print a simple help message. It can print any `Param` | 17 | // `clap.usageToFile` is a function that can print a simple usage string. It can print any |
| 18 | // where `Id` has a `value` method (`Param(Help)` is one such parameter). | 18 | // `Param` where `Id` has a `value` method (`Param(Help)` is one such parameter). |
| 19 | if (res.args.help != 0) { | 19 | if (res.args.help != 0) |
| 20 | var buf: [1024]u8 = undefined; | 20 | return clap.usageToFile(.stdout(), clap.Help, ¶ms); |
| 21 | var stderr = std.fs.File.stderr().writer(&buf); | ||
| 22 | clap.usage(&stderr.interface, clap.Help, ¶ms) catch {}; | ||
| 23 | try stderr.interface.flush(); | ||
| 24 | return; | ||
| 25 | } | ||
| 26 | } | 21 | } |
| 27 | 22 | ||
| 28 | const clap = @import("clap"); | 23 | const clap = @import("clap"); |