diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 54 |
1 files changed, 29 insertions, 25 deletions
| @@ -32,13 +32,14 @@ const io = std.io; | |||
| 32 | 32 | ||
| 33 | pub fn main() !void { | 33 | pub fn main() !void { |
| 34 | // First we specify what parameters our program can take. | 34 | // First we specify what parameters our program can take. |
| 35 | // We can use `parseParam` to parse a string to a `Param(Help)` | 35 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` |
| 36 | const params = comptime [_]clap.Param(clap.Help){ | 36 | const params = comptime clap.parseParamsComptime( |
| 37 | clap.parseParam("-h, --help Display this help and exit.") catch unreachable, | 37 | \\-h, --help Display this help and exit. |
| 38 | clap.parseParam("-n, --number <usize> An option parameter, which takes a value.") catch unreachable, | 38 | \\-n, --number <usize> An option parameter, which takes a value. |
| 39 | clap.parseParam("-s, --string <str>... An option parameter which can be specified multiple times.") catch unreachable, | 39 | \\-s, --string <str>... An option parameter which can be specified multiple times. |
| 40 | clap.parseParam("<str>...") catch unreachable, | 40 | \\<str>... |
| 41 | }; | 41 | \\ |
| 42 | ); | ||
| 42 | 43 | ||
| 43 | // Initalize our diagnostics, which can be used for reporting useful errors. | 44 | // Initalize our diagnostics, which can be used for reporting useful errors. |
| 44 | // This is optional. You can also pass `.{}` to `clap.parse` if you don't | 45 | // This is optional. You can also pass `.{}` to `clap.parse` if you don't |
| @@ -73,8 +74,8 @@ The fields in `args` are typed. The type is based on the name of the value the p | |||
| 73 | Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. | 74 | Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. |
| 74 | 75 | ||
| 75 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which | 76 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which |
| 76 | contains a parser that returns `usize`. You can pass in something other than `clap.parsers.default` | 77 | contains a parser that returns `usize`. You can pass in something other than |
| 77 | if you want some other mapping. | 78 | `clap.parsers.default` if you want some other mapping. |
| 78 | 79 | ||
| 79 | ```zig | 80 | ```zig |
| 80 | const clap = @import("clap"); | 81 | const clap = @import("clap"); |
| @@ -86,13 +87,14 @@ const process = std.process; | |||
| 86 | 87 | ||
| 87 | pub fn main() !void { | 88 | pub fn main() !void { |
| 88 | // First we specify what parameters our program can take. | 89 | // First we specify what parameters our program can take. |
| 89 | // We can use `parseParam` to parse a string to a `Param(Help)` | 90 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` |
| 90 | const params = comptime [_]clap.Param(clap.Help){ | 91 | const params = comptime clap.parseParamsComptime( |
| 91 | clap.parseParam("-h, --help Display this help and exit.") catch unreachable, | 92 | \\-h, --help Display this help and exit. |
| 92 | clap.parseParam("-n, --number <INT> An option parameter, which takes a value.") catch unreachable, | 93 | \\-n, --number <INT> An option parameter, which takes a value. |
| 93 | clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, | 94 | \\-s, --string <STR>... An option parameter which can be specified multiple times. |
| 94 | clap.parseParam("<FILE>...") catch unreachable, | 95 | \\<FILE>... |
| 95 | }; | 96 | \\ |
| 97 | ); | ||
| 96 | 98 | ||
| 97 | // Declare our own parsers which are used to map the argument strings to other | 99 | // Declare our own parsers which are used to map the argument strings to other |
| 98 | // types. | 100 | // types. |
| @@ -205,10 +207,11 @@ const clap = @import("clap"); | |||
| 205 | const std = @import("std"); | 207 | const std = @import("std"); |
| 206 | 208 | ||
| 207 | pub fn main() !void { | 209 | pub fn main() !void { |
| 208 | const params = comptime [_]clap.Param(clap.Help){ | 210 | const params = comptime clap.parseParamsComptime( |
| 209 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, | 211 | \\-h, --help Display this help and exit. |
| 210 | clap.parseParam("-v, --version Output version information and exit.") catch unreachable, | 212 | \\-v, --version Output version information and exit. |
| 211 | }; | 213 | \\ |
| 214 | ); | ||
| 212 | 215 | ||
| 213 | var res = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{}); | 216 | var res = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{}); |
| 214 | defer res.deinit(); | 217 | defer res.deinit(); |
| @@ -238,11 +241,12 @@ const clap = @import("clap"); | |||
| 238 | const std = @import("std"); | 241 | const std = @import("std"); |
| 239 | 242 | ||
| 240 | pub fn main() !void { | 243 | pub fn main() !void { |
| 241 | const params = comptime [_]clap.Param(clap.Help){ | 244 | const params = comptime clap.parseParamsComptime( |
| 242 | clap.parseParam("-h, --help Display this help and exit.") catch unreachable, | 245 | \\-h, --help Display this help and exit. |
| 243 | clap.parseParam("-v, --version Output version information and exit.") catch unreachable, | 246 | \\-v, --version Output version information and exit. |
| 244 | clap.parseParam(" --value <str> An option parameter, which takes a value.") catch unreachable, | 247 | \\ --value <str> An option parameter, which takes a value. |
| 245 | }; | 248 | \\ |
| 249 | ); | ||
| 246 | 250 | ||
| 247 | var res = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{}); | 251 | var res = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{}); |
| 248 | defer res.deinit(); | 252 | defer res.deinit(); |