summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2020-03-05 23:24:36 +0100
committerGravatar Jimmi Holst Christensen2020-03-05 23:24:36 +0100
commitcc056cf4232721b62b76428d1ada447eecd98421 (patch)
tree56e859d0f91b372c50d6b35818877a4476ded5a1 /example
parentAdd clap.parse as the simplest way of using the lib (diff)
downloadzig-clap-cc056cf4232721b62b76428d1ada447eecd98421.tar.gz
zig-clap-cc056cf4232721b62b76428d1ada447eecd98421.tar.xz
zig-clap-cc056cf4232721b62b76428d1ada447eecd98421.zip
Add clap.usage
Diffstat (limited to '')
-rw-r--r--example/README.md.template23
-rw-r--r--example/usage.zig20
2 files changed, 43 insertions, 0 deletions
diff --git a/example/README.md.template b/example/README.md.template
index 1fd90b0..d1d45e5 100644
--- a/example/README.md.template
+++ b/example/README.md.template
@@ -87,3 +87,26 @@ The `helpEx` is the generic version of `help`. It can print a help message for a
87 87
88The `helpFull` is even more generic, allowing the functions that get the help and value strings 88The `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. 89to return errors and take a context as a parameter.
90
91### `usage`
92
93The `usage`, `usageEx` and `usageFull` are functions for printing a simple list of all parameters the
94program can take.
95
96```zig
97{}
98```
99
100```
101[-hv] [--value <N>]
102```
103
104The `usage` functions are the simplest to call. It only takes an `OutStream` and a slice of
105`Param(Help)`.
106
107The `usageEx` is the generic version of `usage`. It can print a usage message for any
108`Param` give that the caller provides functions for getting the usage and value strings.
109
110The `usageFull` is even more generic, allowing the functions that get the usage and value strings
111to return errors and take a context as a parameter.
112
diff --git a/example/usage.zig b/example/usage.zig
new file mode 100644
index 0000000..734d741
--- /dev/null
+++ b/example/usage.zig
@@ -0,0 +1,20 @@
1const std = @import("std");
2const clap = @import("clap");
3
4pub fn main() !void {
5 const stderr_file = try std.io.getStdErr();
6 var stderr_out_stream = stderr_file.outStream();
7 const stderr = &stderr_out_stream.stream;
8
9 // clap.usage is a function that can print a simple usage message, given a
10 // slice of Param(Help). There is also a usageEx, which can print a
11 // usage message for any Param, but it is more verbose to call.
12 try clap.usage(
13 stderr,
14 comptime [_]clap.Param(clap.Help){
15 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
16 clap.parseParam("-v, --version Output version information and exit.") catch unreachable,
17 clap.parseParam(" --value <N> Output version information and exit.") catch unreachable,
18 },
19 );
20}