summaryrefslogtreecommitdiff
path: root/example/usage.zig
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/usage.zig
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 'example/usage.zig')
-rw-r--r--example/usage.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/example/usage.zig b/example/usage.zig
index 368a6b3..20d4736 100644
--- a/example/usage.zig
+++ b/example/usage.zig
@@ -3,17 +3,17 @@ const std = @import("std");
3 3
4pub fn main() !void { 4pub fn main() !void {
5 const params = comptime [_]clap.Param(clap.Help){ 5 const params = comptime [_]clap.Param(clap.Help){
6 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, 6 clap.parseParam("-h, --help Display this help and exit.") catch unreachable,
7 clap.parseParam("-v, --version Output version information and exit. ") catch unreachable, 7 clap.parseParam("-v, --version Output version information and exit.") catch unreachable,
8 clap.parseParam(" --value <N> An option parameter, which takes a value.") catch unreachable, 8 clap.parseParam(" --value <str> An option parameter, which takes a value.") catch unreachable,
9 }; 9 };
10 10
11 var args = try clap.parse(clap.Help, &params, .{}); 11 var res = try clap.parse(clap.Help, &params, clap.parsers.default, .{});
12 defer args.deinit(); 12 defer res.deinit();
13 13
14 // clap.usage is a function that can print a simple usage message, given a 14 // clap.usage is a function that can print a simple usage message, given a
15 // slice of Param(Help). There is also a usageEx, which can print a 15 // slice of Param(Help). There is also a usageEx, which can print a
16 // usage message for any Param, but it is more verbose to call. 16 // usage message for any Param, but it is more verbose to call.
17 if (args.flag("--help")) 17 if (res.args.help)
18 return clap.usage(std.io.getStdErr().writer(), &params); 18 return clap.usage(std.io.getStdErr().writer(), clap.Help, &params);
19} 19}