diff options
| author | 2019-11-27 23:13:31 +0900 | |
|---|---|---|
| committer | 2019-11-27 23:13:31 +0900 | |
| commit | a305e818bd986c599fff17141617bc4f890276cf (patch) | |
| tree | ff0a5c133c271d83de3e71ebc023ffc08bb1e3c9 /example/README.md.template | |
| parent | Breaking: OsIterator will now get the exe on init (diff) | |
| download | zig-clap-a305e818bd986c599fff17141617bc4f890276cf.tar.gz zig-clap-a305e818bd986c599fff17141617bc4f890276cf.tar.xz zig-clap-a305e818bd986c599fff17141617bc4f890276cf.zip | |
Add clap.parse as the simplest way of using the lib
Diffstat (limited to '')
| -rw-r--r-- | example/README.md.template | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/example/README.md.template b/example/README.md.template index 373a037..1fd90b0 100644 --- a/example/README.md.template +++ b/example/README.md.template | |||
| @@ -15,45 +15,55 @@ A simple and easy to use command line argument parser library for Zig. | |||
| 15 | 15 | ||
| 16 | ## Examples | 16 | ## Examples |
| 17 | 17 | ||
| 18 | ### `StreamingClap` | 18 | ### `clap.parse` |
| 19 | 19 | ||
| 20 | The `StreamingClap` is the base of all the other parsers. It's a streaming parser that uses an | 20 | The simplest way to use this library is to just call the `clap.parse` function. |
| 21 | `args.Iterator` to provide it with arguments lazily. | ||
| 22 | 21 | ||
| 23 | ```zig | 22 | ```zig |
| 24 | {} | 23 | {} |
| 25 | ``` | 24 | ``` |
| 26 | 25 | ||
| 27 | ### `ComptimeClap` | 26 | The data structure returned has lookup speed on par with array access (`arr[i]`) and validates |
| 28 | 27 | that the strings you pass to `option` and `flag` are actually parameters that the program can take: | |
| 29 | The `ComptimeClap` is a wrapper for `StreamingClap`, which parses all the arguments and makes | ||
| 30 | them available through three functions (`flag`, `option`, `positionals`). | ||
| 31 | |||
| 32 | ```zig | ||
| 33 | {} | ||
| 34 | ``` | ||
| 35 | |||
| 36 | The data structure returned from this parser has lookup speed on par with array access (`arr[i]`) | ||
| 37 | and validates that the strings you pass to `option` and `flag` are actually parameters that the | ||
| 38 | program can take: | ||
| 39 | 28 | ||
| 40 | ```zig | 29 | ```zig |
| 41 | {} | 30 | {} |
| 42 | ``` | 31 | ``` |
| 43 | 32 | ||
| 44 | ``` | 33 | ``` |
| 45 | zig-clap/src/comptime.zig:109:17: error: --helps is not a parameter. | 34 | zig-clap/clap/comptime.zig:109:17: error: --helps is not a parameter. |
| 46 | @compileError(name ++ " is not a parameter."); | 35 | @compileError(name ++ " is not a parameter."); |
| 47 | ^ | 36 | ^ |
| 48 | zig-clap/src/comptime.zig:77:45: note: called from here | 37 | zig-clap/clap/comptime.zig:77:45: note: called from here |
| 49 | const param = comptime findParam(name); | 38 | const param = comptime findParam(name); |
| 50 | ^ | 39 | ^ |
| 51 | zig-clap/example/comptime-clap-error.zig:18:18: note: called from here | 40 | zig-clap/clap.zig:238:31: note: called from here |
| 41 | return a.clap.flag(name); | ||
| 42 | ^ | ||
| 43 | zig-clap/example/simple-error.zig:16:18: note: called from here | ||
| 52 | _ = args.flag("--helps"); | 44 | _ = args.flag("--helps"); |
| 53 | ^ | ||
| 54 | ``` | 45 | ``` |
| 55 | 46 | ||
| 56 | Ofc, this limits you to parameters that are comptime known. | 47 | ### `ComptimeClap` |
| 48 | |||
| 49 | The `ComptimeClap` is the parser used by `clap.parse`. It allows the user to use a custom argument | ||
| 50 | iterator. | ||
| 51 | |||
| 52 | ```zig | ||
| 53 | {} | ||
| 54 | ``` | ||
| 55 | |||
| 56 | ### `StreamingClap` | ||
| 57 | |||
| 58 | The `StreamingClap` is the base of all the other parsers. It's a streaming parser that uses an | ||
| 59 | `args.Iterator` to provide it with arguments lazily. | ||
| 60 | |||
| 61 | ```zig | ||
| 62 | {} | ||
| 63 | ``` | ||
| 64 | |||
| 65 | Currently, this parse is the only parser that allow an array of `Param` that | ||
| 66 | is generated at runtime. | ||
| 57 | 67 | ||
| 58 | ### `help` | 68 | ### `help` |
| 59 | 69 | ||