summaryrefslogtreecommitdiff
path: root/example/simple.zig
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2022-02-25 19:44:52 +0100
committerGravatar Jimmi Holst Christensen2022-02-25 19:44:52 +0100
commitc06c93608cb3befe77c78ba25c70b14db6f7b319 (patch)
tree3598bbd00512eb5baa6da004ae7e42cd8005c3eb /example/simple.zig
parentChange clap into generating a struct (diff)
downloadzig-clap-c06c93608cb3befe77c78ba25c70b14db6f7b319.tar.gz
zig-clap-c06c93608cb3befe77c78ba25c70b14db6f7b319.tar.xz
zig-clap-c06c93608cb3befe77c78ba25c70b14db6f7b319.zip
Revert "Change clap into generating a struct"
This reverts commit cfaac64c404fb1c2e892880410aa3b7dd881ea58.
Diffstat (limited to 'example/simple.zig')
-rw-r--r--example/simple.zig20
1 files changed, 10 insertions, 10 deletions
diff --git a/example/simple.zig b/example/simple.zig
index c37e896..ff6d301 100644
--- a/example/simple.zig
+++ b/example/simple.zig
@@ -8,29 +8,29 @@ pub fn main() !void {
8 // First we specify what parameters our program can take. 8 // First we specify what parameters our program can take.
9 // We can use `parseParam` to parse a string to a `Param(Help)` 9 // We can use `parseParam` to parse a string to a `Param(Help)`
10 const params = comptime [_]clap.Param(clap.Help){ 10 const params = comptime [_]clap.Param(clap.Help){
11 clap.untyped.parseParam("-h, --help Display this help and exit.") catch unreachable, 11 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
12 clap.untyped.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, 12 clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable,
13 clap.untyped.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, 13 clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable,
14 clap.untyped.parseParam("<POS>...") catch unreachable, 14 clap.parseParam("<POS>...") catch unreachable,
15 }; 15 };
16 16
17 // Initalize our diagnostics, which can be used for reporting useful errors. 17 // Initalize our diagnostics, which can be used for reporting useful errors.
18 // This is optional. You can also pass `.{}` to `clap.parse` if you don't 18 // This is optional. You can also pass `.{}` to `clap.parse` if you don't
19 // care about the extra information `Diagnostics` provides. 19 // care about the extra information `Diagnostics` provides.
20 var diag = clap.Diagnostic{}; 20 var diag = clap.Diagnostic{};
21 var res = clap.untyped.parse(clap.Help, &params, .{ .diagnostic = &diag }) catch |err| { 21 var args = clap.parse(clap.Help, &params, .{ .diagnostic = &diag }) catch |err| {
22 // Report useful error and exit 22 // Report useful error and exit
23 diag.report(io.getStdErr().writer(), err) catch {}; 23 diag.report(io.getStdErr().writer(), err) catch {};
24 return err; 24 return err;
25 }; 25 };
26 defer res.deinit(); 26 defer args.deinit();
27 27
28 if (res.args.help) 28 if (args.flag("--help"))
29 debug.print("--help\n", .{}); 29 debug.print("--help\n", .{});
30 if (res.args.number) |n| 30 if (args.option("--number")) |n|
31 debug.print("--number = {s}\n", .{n}); 31 debug.print("--number = {s}\n", .{n});
32 for (res.args.string) |s| 32 for (args.options("--string")) |s|
33 debug.print("--string = {s}\n", .{s}); 33 debug.print("--string = {s}\n", .{s});
34 for (res.positionals) |pos| 34 for (args.positionals()) |pos|
35 debug.print("{s}\n", .{pos}); 35 debug.print("{s}\n", .{pos});
36} 36}