summaryrefslogtreecommitdiff
path: root/example/README.md.template
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2022-02-25 19:40:00 +0100
committerGravatar Komari Spaghetti2022-03-09 18:12:40 +0100
commit5f7b75d5523d9581eca5a72a362868ff517992e8 (patch)
tree5e874f9c935e0d7c838ea5aadf270ce2929f8e8a /example/README.md.template
parentBump actions/checkout from 2.4.0 to 3 (diff)
downloadzig-clap-5f7b75d5523d9581eca5a72a362868ff517992e8.tar.gz
zig-clap-5f7b75d5523d9581eca5a72a362868ff517992e8.tar.xz
zig-clap-5f7b75d5523d9581eca5a72a362868ff517992e8.zip
Allow for clap to parse argument values into types
This changes - `.flag`, `.option`, `.options` and `.positionals` are now just fields you access on the result of `parse` and `parseEx`. - `clap.ComptimeClap` has been removed. - `clap.StreamingClap` is now called `clap.streaming.Clap` - `parse` and `parseEx` now takes a `value_parsers` argument that provides the parsers to parse values. - Remove `helpEx`, `helpFull`, `usageEx` and `usageFull`. They now just expect `Id` to have methods for getting the description and value texts.
Diffstat (limited to '')
-rw-r--r--example/README.md.template51
1 files changed, 17 insertions, 34 deletions
diff --git a/example/README.md.template b/example/README.md.template
index 7f5c545..9fbc1cc 100644
--- a/example/README.md.template
+++ b/example/README.md.template
@@ -27,33 +27,24 @@ The simplest way to use this library is to just call the `clap.parse` function.
27{s} 27{s}
28``` 28```
29 29
30The data structure returned has lookup speed on par with array access (`arr[i]`) and validates 30The result will contain an `args` field and a `positionals` field. `args` will have one field
31that the strings you pass to `option`, `options` and `flag` are actually parameters that the 31for each none positional parameter of your program. The name of the field will be the longest
32program can take: 32name of the parameter.
33
34The fields in `args` are typed. The type is based on the name of the value the parameter takes.
35Since `--number` takes a `usize` the field `res.args.number` has the type `usize`.
36
37Note that this is only the case because `clap.parsers.default` has a field called `usize` which
38contains a parser that returns `usize`. You can pass in something other than `clap.parsers.default`
39if you want some other mapping.
33 40
34```zig 41```zig
35{s} 42{s}
36``` 43```
37 44
38``` 45### `streaming.Clap`
39zig-clap/clap/comptime.zig:109:17: error: --helps is not a parameter.
40 @compileError(name ++ " is not a parameter.");
41 ^
42zig-clap/clap/comptime.zig:77:45: note: called from here
43 const param = comptime findParam(name);
44 ^
45zig-clap/clap.zig:238:31: note: called from here
46 return a.clap.flag(name);
47 ^
48zig-clap/example/simple-error.zig:16:18: note: called from here
49 _ = args.flag("--helps");
50```
51
52There is also a `parseEx` variant that takes an argument iterator.
53 46
54### `StreamingClap` 47The `streaming.Clap` is the base of all the other parsers. It's a streaming parser that uses an
55
56The `StreamingClap` is the base of all the other parsers. It's a streaming parser that uses an
57`args.Iterator` to provide it with arguments lazily. 48`args.Iterator` to provide it with arguments lazily.
58 49
59```zig 50```zig
@@ -65,8 +56,9 @@ is generated at runtime.
65 56
66### `help` 57### `help`
67 58
68The `help`, `helpEx` and `helpFull` are functions for printing a simple list of all parameters the 59The `help` prints a simple list of all parameters the program can take. It expects the
69program can take. 60`Id` to have a `description` method and an `value` method so that it can provide that
61in the output.
70 62
71```zig 63```zig
72{s} 64{s}
@@ -78,19 +70,10 @@ $ zig-out/bin/help --help
78 -v, --version Output version information and exit. 70 -v, --version Output version information and exit.
79``` 71```
80 72
81The `help` functions are the simplest to call. It only takes an `OutStream` and a slice of
82`Param(Help)`.
83
84The `helpEx` is the generic version of `help`. It can print a help message for any
85`Param` give that the caller provides functions for getting the help and value strings.
86
87The `helpFull` is even more generic, allowing the functions that get the help and value strings
88to return errors and take a context as a parameter.
89
90### `usage` 73### `usage`
91 74
92The `usage`, `usageEx` and `usageFull` are functions for printing a small abbreviated version 75The `usage` prints a small abbreviated version of the help message. It expects the `Id`
93of the help message. 76to have a `value` method so it can provide that in the output.
94 77
95```zig 78```zig
96{s} 79{s}