summaryrefslogtreecommitdiff
path: root/example/README.md.template
diff options
context:
space:
mode:
authorGravatar Jimmi HC2019-06-21 19:15:32 +0200
committerGravatar Jimmi HC2019-06-21 19:15:32 +0200
commit56e7be2835311888ef43f403e5d6bc2118c953fe (patch)
treea700e966b79ec441f8936c667bd325e37c4a61dc /example/README.md.template
parentupdated to newest version of zig (diff)
downloadzig-clap-56e7be2835311888ef43f403e5d6bc2118c953fe.tar.gz
zig-clap-56e7be2835311888ef43f403e5d6bc2118c953fe.tar.xz
zig-clap-56e7be2835311888ef43f403e5d6bc2118c953fe.zip
Embed examples in README during build
fixes #11
Diffstat (limited to 'example/README.md.template')
-rw-r--r--example/README.md.template77
1 files changed, 77 insertions, 0 deletions
diff --git a/example/README.md.template b/example/README.md.template
new file mode 100644
index 0000000..88914fb
--- /dev/null
+++ b/example/README.md.template
@@ -0,0 +1,77 @@
1# zig-clap
2
3A simple and easy to use command line argument parser library for Zig.
4
5## Features
6
7* Short arguments `-a`
8 * Chaining `-abc` where `a` and `b` does not take values.
9* Long arguments `--long`
10* Supports both passing values using spacing and `=` (`-a 100`, `-a=100`)
11 * Short args also support passing values with no spacing or `=` (`-a100`)
12 * This all works with chaining (`-ba 100`, `-ba=100`, `-ba100`)
13
14## Examples
15
16### `StreamingClap`
17
18The `StreamingClap` is the base of all the other parsers. It's a streaming parser that uses an
19`args.Iterator` to provide it with arguments lazily.
20
21```zig
22{}
23```
24
25### `ComptimeClap`
26
27The `ComptimeClap` is a wrapper for `StreamingClap`, which parses all the arguments and makes
28them available through three functions (`flag`, `option`, `positionals`).
29
30```zig
31{}
32```
33
34The data structure returned from this parser has lookup speed on par with array access (`arr[i]`)
35and validates that the strings you pass to `option` and `flag` are actually parameters that the
36program can take:
37
38```zig
39{}
40```
41
42```
43zig-clap/src/comptime.zig:116:17: error: --helps is not a parameter.
44 @compileError(name ++ " is not a parameter.");
45 ^
46zig-clap/src/comptime.zig:84:45: note: called from here
47 const param = comptime findParam(name);
48 ^
49zig-clap/example/comptime-clap-error.zig:22:18: note: called from here
50 _ = args.flag("--helps");
51 ^
52```
53
54Ofc, this limits you to parameters that are comptime known.
55
56### `help`
57
58The `help`, `helpEx` and `helpFull` are functions for printing a simple list of all parameters the
59program can take.
60
61```zig
62{}
63```
64
65```
66 -h, --help Display this help and exit.
67 -v, --version Output version information and exit.
68```
69
70The `help` function is the simplest to call. It only takes an `OutStream` and a slice of
71`Param([]const u8)`. This function assumes that the id of each parameter is the help message.
72
73The `helpEx` is the generic version of `help`. It can print a help message for any
74`Param` give that the caller provides functions for getting the help and value strings.
75
76The `helpFull` is even more generic, allowing the functions that get the help and value strings
77to return errors and take a context as a parameter.