summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2020-04-18 16:43:18 +0200
committerGravatar Jimmi Holst Christensen2020-04-18 16:43:18 +0200
commit0b1dd505dda4c2f3076cf9d074d20666cefa0e20 (patch)
tree5b24f351c47e69f1836d7a696d63a71d9081381c /example
parentMerge pull request #17 from joachimschmidt557/zig-master (diff)
parentBetter readme for usage (diff)
downloadzig-clap-0b1dd505dda4c2f3076cf9d074d20666cefa0e20.tar.gz
zig-clap-0b1dd505dda4c2f3076cf9d074d20666cefa0e20.tar.xz
zig-clap-0b1dd505dda4c2f3076cf9d074d20666cefa0e20.zip
Merge branch 'master' into zig-master
Diffstat (limited to 'example')
-rw-r--r--example/README.md.template18
-rw-r--r--example/usage.zig18
2 files changed, 36 insertions, 0 deletions
diff --git a/example/README.md.template b/example/README.md.template
index 1fd90b0..2afbe86 100644
--- a/example/README.md.template
+++ b/example/README.md.template
@@ -2,6 +2,10 @@
2 2
3A simple and easy to use command line argument parser library for Zig. 3A simple and easy to use command line argument parser library for Zig.
4 4
5Looking for a version that works with `zig master`? The `zig-master` branch has
6you covered. It is maintained by people who live at head (not me) and is merged
7into master on every `zig` release.
8
5## Features 9## Features
6 10
7* Short arguments `-a` 11* Short arguments `-a`
@@ -87,3 +91,17 @@ The `helpEx` is the generic version of `help`. It can print a help message for a
87 91
88The `helpFull` is even more generic, allowing the functions that get the help and value strings 92The `helpFull` is even more generic, allowing the functions that get the help and value strings
89to return errors and take a context as a parameter. 93to return errors and take a context as a parameter.
94
95### `usage`
96
97The `usage`, `usageEx` and `usageFull` are functions for printing a small abbreviated version
98of the help message.
99
100```zig
101{}
102```
103
104```
105[-hv] [--value <N>]
106```
107
diff --git a/example/usage.zig b/example/usage.zig
new file mode 100644
index 0000000..25e1a34
--- /dev/null
+++ b/example/usage.zig
@@ -0,0 +1,18 @@
1const std = @import("std");
2const clap = @import("clap");
3
4pub fn main() !void {
5 const stderr = std.io.getStdErr().outStream();
6
7 // clap.usage is a function that can print a simple usage message, given a
8 // slice of Param(Help). There is also a usageEx, which can print a
9 // usage message for any Param, but it is more verbose to call.
10 try clap.usage(
11 stderr,
12 comptime &[_]clap.Param(clap.Help){
13 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
14 clap.parseParam("-v, --version Output version information and exit.") catch unreachable,
15 clap.parseParam(" --value <N> Output version information and exit.") catch unreachable,
16 },
17 );
18}