diff options
| author | 2020-03-05 23:24:36 +0100 | |
|---|---|---|
| committer | 2020-03-05 23:24:36 +0100 | |
| commit | cc056cf4232721b62b76428d1ada447eecd98421 (patch) | |
| tree | 56e859d0f91b372c50d6b35818877a4476ded5a1 /README.md | |
| parent | Add clap.parse as the simplest way of using the lib (diff) | |
| download | zig-clap-cc056cf4232721b62b76428d1ada447eecd98421.tar.gz zig-clap-cc056cf4232721b62b76428d1ada447eecd98421.tar.xz zig-clap-cc056cf4232721b62b76428d1ada447eecd98421.zip | |
Add clap.usage
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 43 |
1 files changed, 43 insertions, 0 deletions
| @@ -232,3 +232,46 @@ The `helpEx` is the generic version of `help`. It can print a help message for a | |||
| 232 | 232 | ||
| 233 | The `helpFull` is even more generic, allowing the functions that get the help and value strings | 233 | The `helpFull` is even more generic, allowing the functions that get the help and value strings |
| 234 | to return errors and take a context as a parameter. | 234 | to return errors and take a context as a parameter. |
| 235 | |||
| 236 | ### `usage` | ||
| 237 | |||
| 238 | The `usage`, `usageEx` and `usageFull` are functions for printing a simple list of all parameters the | ||
| 239 | program can take. | ||
| 240 | |||
| 241 | ```zig | ||
| 242 | const std = @import("std"); | ||
| 243 | const clap = @import("clap"); | ||
| 244 | |||
| 245 | pub fn main() !void { | ||
| 246 | const stderr_file = try std.io.getStdErr(); | ||
| 247 | var stderr_out_stream = stderr_file.outStream(); | ||
| 248 | const stderr = &stderr_out_stream.stream; | ||
| 249 | |||
| 250 | // clap.usage is a function that can print a simple usage message, given a | ||
| 251 | // slice of Param(Help). There is also a usageEx, which can print a | ||
| 252 | // usage message for any Param, but it is more verbose to call. | ||
| 253 | try clap.usage( | ||
| 254 | stderr, | ||
| 255 | comptime [_]clap.Param(clap.Help){ | ||
| 256 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, | ||
| 257 | clap.parseParam("-v, --version Output version information and exit.") catch unreachable, | ||
| 258 | clap.parseParam(" --value <N> Output version information and exit.") catch unreachable, | ||
| 259 | }, | ||
| 260 | ); | ||
| 261 | } | ||
| 262 | |||
| 263 | ``` | ||
| 264 | |||
| 265 | ``` | ||
| 266 | [-hv] [--value <N>] | ||
| 267 | ``` | ||
| 268 | |||
| 269 | The `usage` functions are the simplest to call. It only takes an `OutStream` and a slice of | ||
| 270 | `Param(Help)`. | ||
| 271 | |||
| 272 | The `usageEx` is the generic version of `usage`. It can print a usage message for any | ||
| 273 | `Param` give that the caller provides functions for getting the usage and value strings. | ||
| 274 | |||
| 275 | The `usageFull` is even more generic, allowing the functions that get the usage and value strings | ||
| 276 | to return errors and take a context as a parameter. | ||
| 277 | |||