From 4e293092fc56ebf46d9c17e4e203ca54c63a0b09 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Thu, 24 Oct 2024 15:36:55 +0200 Subject: feat: Support multiple positionals of different types --- example/README.md.template | 6 +++--- example/simple-ex.zig | 2 +- example/simple.zig | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'example') diff --git a/example/README.md.template b/example/README.md.template index dda0cc9..d234dcd 100644 --- a/example/README.md.template +++ b/example/README.md.template @@ -61,10 +61,10 @@ The simplest way to use this library is to just call the `clap.parse` function. The result will contain an `args` field and a `positionals` field. `args` will have one field for each none positional parameter of your program. The name of the field will be the longest -name of the parameter. +name of the parameter. `positionals` be a tuple with one field for each positional parameter. -The fields in `args` are typed. The type is based on the name of the value the parameter takes. -Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. +The fields in `args` and `psotionals` are typed. The type is based on the name of the value the +parameter takes. Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. Note that this is only the case because `clap.parsers.default` has a field called `usize` which contains a parser that returns `usize`. You can pass in something other than diff --git a/example/simple-ex.zig b/example/simple-ex.zig index 4ca9791..154e486 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig @@ -44,7 +44,7 @@ pub fn main() !void { std.debug.print("--answer = {s}\n", .{@tagName(a)}); for (res.args.string) |s| std.debug.print("--string = {s}\n", .{s}); - for (res.positionals) |pos| + for (res.positionals[0]) |pos| std.debug.print("{s}\n", .{pos}); } diff --git a/example/simple.zig b/example/simple.zig index 7f1bfc0..74157a6 100644 --- a/example/simple.zig +++ b/example/simple.zig @@ -32,7 +32,7 @@ pub fn main() !void { std.debug.print("--number = {}\n", .{n}); for (res.args.string) |s| std.debug.print("--string = {s}\n", .{s}); - for (res.positionals) |pos| + for (res.positionals[0]) |pos| std.debug.print("{s}\n", .{pos}); } -- cgit v1.2.3