diff options
| author | 2020-04-18 16:43:18 +0200 | |
|---|---|---|
| committer | 2020-04-18 16:43:18 +0200 | |
| commit | 0b1dd505dda4c2f3076cf9d074d20666cefa0e20 (patch) | |
| tree | 5b24f351c47e69f1836d7a696d63a71d9081381c /README.md | |
| parent | Merge pull request #17 from joachimschmidt557/zig-master (diff) | |
| parent | Better readme for usage (diff) | |
| download | zig-clap-0b1dd505dda4c2f3076cf9d074d20666cefa0e20.tar.gz zig-clap-0b1dd505dda4c2f3076cf9d074d20666cefa0e20.tar.xz zig-clap-0b1dd505dda4c2f3076cf9d074d20666cefa0e20.zip | |
Merge branch 'master' into zig-master
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 36 |
1 files changed, 36 insertions, 0 deletions
| @@ -2,6 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | A simple and easy to use command line argument parser library for Zig. | 3 | A simple and easy to use command line argument parser library for Zig. |
| 4 | 4 | ||
| 5 | Looking for a version that works with `zig master`? The `zig-master` branch has | ||
| 6 | you covered. It is maintained by people who live at head (not me) and is merged | ||
| 7 | into master on every `zig` release. | ||
| 8 | |||
| 5 | ## Features | 9 | ## Features |
| 6 | 10 | ||
| 7 | * Short arguments `-a` | 11 | * Short arguments `-a` |
| @@ -231,3 +235,35 @@ The `helpEx` is the generic version of `help`. It can print a help message for a | |||
| 231 | 235 | ||
| 232 | The `helpFull` is even more generic, allowing the functions that get the help and value strings | 236 | The `helpFull` is even more generic, allowing the functions that get the help and value strings |
| 233 | to return errors and take a context as a parameter. | 237 | to return errors and take a context as a parameter. |
| 238 | |||
| 239 | ### `usage` | ||
| 240 | |||
| 241 | The `usage`, `usageEx` and `usageFull` are functions for printing a small abbreviated version | ||
| 242 | of the help message. | ||
| 243 | |||
| 244 | ```zig | ||
| 245 | const std = @import("std"); | ||
| 246 | const clap = @import("clap"); | ||
| 247 | |||
| 248 | pub fn main() !void { | ||
| 249 | const stderr = std.io.getStdErr().outStream(); | ||
| 250 | |||
| 251 | // clap.usage is a function that can print a simple usage message, given a | ||
| 252 | // slice of Param(Help). There is also a usageEx, which can print a | ||
| 253 | // usage message for any Param, but it is more verbose to call. | ||
| 254 | try clap.usage( | ||
| 255 | stderr, | ||
| 256 | comptime &[_]clap.Param(clap.Help){ | ||
| 257 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, | ||
| 258 | clap.parseParam("-v, --version Output version information and exit.") catch unreachable, | ||
| 259 | clap.parseParam(" --value <N> Output version information and exit.") catch unreachable, | ||
| 260 | }, | ||
| 261 | ); | ||
| 262 | } | ||
| 263 | |||
| 264 | ``` | ||
| 265 | |||
| 266 | ``` | ||
| 267 | [-hv] [--value <N>] | ||
| 268 | ``` | ||
| 269 | |||