summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2024-10-24 15:36:55 +0200
committerGravatar Komari Spaghetti2024-10-24 16:35:47 +0200
commit4e293092fc56ebf46d9c17e4e203ca54c63a0b09 (patch)
treefc400c62cb7f96f0cc475162c7084dadb1f3b029 /README.md
parentrefactor: positonals type now depend on the number of values taken (diff)
downloadzig-clap-4e293092fc56ebf46d9c17e4e203ca54c63a0b09.tar.gz
zig-clap-4e293092fc56ebf46d9c17e4e203ca54c63a0b09.tar.xz
zig-clap-4e293092fc56ebf46d9c17e4e203ca54c63a0b09.zip
feat: Support multiple positionals of different types
Diffstat (limited to '')
-rw-r--r--README.md10
1 files changed, 5 insertions, 5 deletions
diff --git a/README.md b/README.md
index c6e14e9..3281d91 100644
--- a/README.md
+++ b/README.md
@@ -90,7 +90,7 @@ pub fn main() !void {
90 std.debug.print("--number = {}\n", .{n}); 90 std.debug.print("--number = {}\n", .{n});
91 for (res.args.string) |s| 91 for (res.args.string) |s|
92 std.debug.print("--string = {s}\n", .{s}); 92 std.debug.print("--string = {s}\n", .{s});
93 for (res.positionals) |pos| 93 for (res.positionals[0]) |pos|
94 std.debug.print("{s}\n", .{pos}); 94 std.debug.print("{s}\n", .{pos});
95} 95}
96 96
@@ -101,10 +101,10 @@ const std = @import("std");
101 101
102The result will contain an `args` field and a `positionals` field. `args` will have one field 102The result will contain an `args` field and a `positionals` field. `args` will have one field
103for each none positional parameter of your program. The name of the field will be the longest 103for each none positional parameter of your program. The name of the field will be the longest
104name of the parameter. 104name of the parameter. `positionals` be a tuple with one field for each positional parameter.
105 105
106The fields in `args` are typed. The type is based on the name of the value the parameter takes. 106The fields in `args` and `psotionals` are typed. The type is based on the name of the value the
107Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. 107parameter takes. Since `--number` takes a `usize` the field `res.args.number` has the type `usize`.
108 108
109Note that this is only the case because `clap.parsers.default` has a field called `usize` which 109Note that this is only the case because `clap.parsers.default` has a field called `usize` which
110contains a parser that returns `usize`. You can pass in something other than 110contains a parser that returns `usize`. You can pass in something other than
@@ -157,7 +157,7 @@ pub fn main() !void {
157 std.debug.print("--answer = {s}\n", .{@tagName(a)}); 157 std.debug.print("--answer = {s}\n", .{@tagName(a)});
158 for (res.args.string) |s| 158 for (res.args.string) |s|
159 std.debug.print("--string = {s}\n", .{s}); 159 std.debug.print("--string = {s}\n", .{s});
160 for (res.positionals) |pos| 160 for (res.positionals[0]) |pos|
161 std.debug.print("{s}\n", .{pos}); 161 std.debug.print("{s}\n", .{pos});
162} 162}
163 163