diff options
Diffstat (limited to 'example')
| -rw-r--r-- | example/README.md.template | 4 | ||||
| -rw-r--r-- | example/comptime-clap.zig | 19 | ||||
| -rw-r--r-- | example/help.zig | 14 |
3 files changed, 12 insertions, 25 deletions
diff --git a/example/README.md.template b/example/README.md.template index 88914fb..446fd78 100644 --- a/example/README.md.template +++ b/example/README.md.template | |||
| @@ -67,8 +67,8 @@ program can take. | |||
| 67 | -v, --version Output version information and exit. | 67 | -v, --version Output version information and exit. |
| 68 | ``` | 68 | ``` |
| 69 | 69 | ||
| 70 | The `help` function is the simplest to call. It only takes an `OutStream` and a slice of | 70 | The `help` functions are 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. | 71 | `Param(Help)`. |
| 72 | 72 | ||
| 73 | The `helpEx` is the generic version of `help`. It can print a help message for any | 73 | The `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. | 74 | `Param` give that the caller provides functions for getting the help and value strings. |
diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig index 0b6d2c4..f73da69 100644 --- a/example/comptime-clap.zig +++ b/example/comptime-clap.zig | |||
| @@ -7,18 +7,11 @@ pub fn main() !void { | |||
| 7 | const allocator = std.heap.direct_allocator; | 7 | const allocator = std.heap.direct_allocator; |
| 8 | 8 | ||
| 9 | // First we specify what parameters our program can take. | 9 | // First we specify what parameters our program can take. |
| 10 | const params = [_]clap.Param([]const u8){ | 10 | // We can use `parseParam` parse a string to a `Param(Help)` |
| 11 | clap.Param([]const u8){ | 11 | const params = comptime [_]clap.Param(clap.Help){ |
| 12 | .id = "Display this help and exit.", | 12 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 13 | .names = clap.Names{ .short = 'h', .long = "help" }, | 13 | clap.parseParam("-n, --number=NUM An option parameter, which takes a value.") catch unreachable, |
| 14 | }, | 14 | clap.Param(clap.Help){ |
| 15 | clap.Param([]const u8){ | ||
| 16 | .id = "An option parameter, which takes a value.", | ||
| 17 | .names = clap.Names{ .short = 'n', .long = "number" }, | ||
| 18 | .takes_value = true, | ||
| 19 | }, | ||
| 20 | clap.Param([]const u8){ | ||
| 21 | .id = "", | ||
| 22 | .takes_value = true, | 15 | .takes_value = true, |
| 23 | }, | 16 | }, |
| 24 | }; | 17 | }; |
| @@ -32,7 +25,7 @@ pub fn main() !void { | |||
| 32 | const exe = try iter.next(); | 25 | const exe = try iter.next(); |
| 33 | 26 | ||
| 34 | // Finally we can parse the arguments | 27 | // Finally we can parse the arguments |
| 35 | var args = try clap.ComptimeClap([]const u8, params).parse(allocator, clap.args.OsIterator, &iter); | 28 | var args = try clap.ComptimeClap(clap.Help, params).parse(allocator, clap.args.OsIterator, &iter); |
| 36 | defer args.deinit(); | 29 | defer args.deinit(); |
| 37 | 30 | ||
| 38 | if (args.flag("--help")) | 31 | if (args.flag("--help")) |
diff --git a/example/help.zig b/example/help.zig index 35c0258..de8a55a 100644 --- a/example/help.zig +++ b/example/help.zig | |||
| @@ -7,19 +7,13 @@ pub fn main() !void { | |||
| 7 | const stderr = &stderr_out_stream.stream; | 7 | const stderr = &stderr_out_stream.stream; |
| 8 | 8 | ||
| 9 | // clap.help is a function that can print a simple help message, given a | 9 | // clap.help is a function that can print a simple help message, given a |
| 10 | // slice of Param([]const u8). There is also a helpEx, which can print a | 10 | // slice of Param(Help). There is also a helpEx, which can print a |
| 11 | // help message for any Param, but it is more verbose to call. | 11 | // help message for any Param, but it is more verbose to call. |
| 12 | try clap.help( | 12 | try clap.help( |
| 13 | stderr, | 13 | stderr, |
| 14 | [_]clap.Param([]const u8){ | 14 | comptime [_]clap.Param(clap.Help){ |
| 15 | clap.Param([]const u8){ | 15 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 16 | .id = "Display this help and exit.", | 16 | clap.parseParam("-v, --version Output version information and exit.") catch unreachable, |
| 17 | .names = clap.Names{ .short = 'h', .long = "help" }, | ||
| 18 | }, | ||
| 19 | clap.Param([]const u8){ | ||
| 20 | .id = "Output version information and exit.", | ||
| 21 | .names = clap.Names{ .short = 'v', .long = "version" }, | ||
| 22 | }, | ||
| 23 | }, | 17 | }, |
| 24 | ); | 18 | ); |
| 25 | } | 19 | } |