diff options
| author | 2025-07-22 10:54:19 +0200 | |
|---|---|---|
| committer | 2025-07-22 10:54:19 +0200 | |
| commit | 0356f53d5bc46011efc6b6ffbfe0b202466d7b4f (patch) | |
| tree | 98efe75192b2aca9f293ec0ce03c78f20a6e1ec3 /README.md | |
| 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 'README.md')
| -rw-r--r-- | README.md | 12 |
1 files changed, 4 insertions, 8 deletions
| @@ -404,14 +404,10 @@ pub fn main() !void { | |||
| 404 | }); | 404 | }); |
| 405 | defer res.deinit(); | 405 | defer res.deinit(); |
| 406 | 406 | ||
| 407 | // `clap.usage` is a function that can print a simple help message. It can print any `Param` | 407 | // `clap.usageToFile` is a function that can print a simple usage string. It can print any |
| 408 | // where `Id` has a `value` method (`Param(Help)` is one such parameter). | 408 | // `Param` where `Id` has a `value` method (`Param(Help)` is one such parameter). |
| 409 | if (res.args.help != 0) { | 409 | if (res.args.help != 0) |
| 410 | var buf: [1024]u8 = undefined; | 410 | return clap.usage(.stdout(), clap.Help, ¶ms); |
| 411 | var stderr = std.fs.File.stderr().writer(&buf); | ||
| 412 | try clap.usage(&stderr.interface, clap.Help, ¶ms); | ||
| 413 | return stderr.interface.flush(); | ||
| 414 | } | ||
| 415 | } | 411 | } |
| 416 | 412 | ||
| 417 | const clap = @import("clap"); | 413 | const clap = @import("clap"); |