summaryrefslogtreecommitdiff
path: root/example/simple-ex.zig
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--example/simple-ex.zig20
1 files changed, 10 insertions, 10 deletions
diff --git a/example/simple-ex.zig b/example/simple-ex.zig
index f1a958d..d2dc77e 100644
--- a/example/simple-ex.zig
+++ b/example/simple-ex.zig
@@ -11,10 +11,10 @@ pub fn main() !void {
11 // First we specify what parameters our program can take. 11 // First we specify what parameters our program can take.
12 // We can use `parseParam` to parse a string to a `Param(Help)` 12 // We can use `parseParam` to parse a string to a `Param(Help)`
13 const params = comptime [_]clap.Param(clap.Help){ 13 const params = comptime [_]clap.Param(clap.Help){
14 clap.untyped.parseParam("-h, --help Display this help and exit.") catch unreachable, 14 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
15 clap.untyped.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, 15 clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable,
16 clap.untyped.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, 16 clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable,
17 clap.untyped.parseParam("<POS>...") catch unreachable, 17 clap.parseParam("<POS>...") catch unreachable,
18 }; 18 };
19 19
20 var iter = try process.ArgIterator.initWithAllocator(allocator); 20 var iter = try process.ArgIterator.initWithAllocator(allocator);
@@ -27,7 +27,7 @@ pub fn main() !void {
27 // This is optional. You can also pass `.{}` to `clap.parse` if you don't 27 // This is optional. You can also pass `.{}` to `clap.parse` if you don't
28 // care about the extra information `Diagnostics` provides. 28 // care about the extra information `Diagnostics` provides.
29 var diag = clap.Diagnostic{}; 29 var diag = clap.Diagnostic{};
30 var res = clap.untyped.parseEx(clap.Help, &params, &iter, .{ 30 var args = clap.parseEx(clap.Help, &params, &iter, .{
31 .allocator = allocator, 31 .allocator = allocator,
32 .diagnostic = &diag, 32 .diagnostic = &diag,
33 }) catch |err| { 33 }) catch |err| {
@@ -35,14 +35,14 @@ pub fn main() !void {
35 diag.report(io.getStdErr().writer(), err) catch {}; 35 diag.report(io.getStdErr().writer(), err) catch {};
36 return err; 36 return err;
37 }; 37 };
38 defer res.deinit(); 38 defer args.deinit();
39 39
40 if (res.args.help) 40 if (args.flag("--help"))
41 debug.print("--help\n", .{}); 41 debug.print("--help\n", .{});
42 if (res.args.number) |n| 42 if (args.option("--number")) |n|
43 debug.print("--number = {s}\n", .{n}); 43 debug.print("--number = {s}\n", .{n});
44 for (res.args.string) |s| 44 for (args.options("--string")) |s|
45 debug.print("--string = {s}\n", .{s}); 45 debug.print("--string = {s}\n", .{s});
46 for (res.positionals) |pos| 46 for (args.positionals()) |pos|
47 debug.print("{s}\n", .{pos}); 47 debug.print("{s}\n", .{pos});
48} 48}