diff options
| author | 2024-10-24 15:36:55 +0200 | |
|---|---|---|
| committer | 2024-10-24 16:35:47 +0200 | |
| commit | 4e293092fc56ebf46d9c17e4e203ca54c63a0b09 (patch) | |
| tree | fc400c62cb7f96f0cc475162c7084dadb1f3b029 /README.md | |
| parent | refactor: positonals type now depend on the number of values taken (diff) | |
| download | zig-clap-4e293092fc56ebf46d9c17e4e203ca54c63a0b09.tar.gz zig-clap-4e293092fc56ebf46d9c17e4e203ca54c63a0b09.tar.xz zig-clap-4e293092fc56ebf46d9c17e4e203ca54c63a0b09.zip | |
feat: Support multiple positionals of different types
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 10 |
1 files changed, 5 insertions, 5 deletions
| @@ -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 | ||
| 102 | The result will contain an `args` field and a `positionals` field. `args` will have one field | 102 | The result will contain an `args` field and a `positionals` field. `args` will have one field |
| 103 | for each none positional parameter of your program. The name of the field will be the longest | 103 | for each none positional parameter of your program. The name of the field will be the longest |
| 104 | name of the parameter. | 104 | name of the parameter. `positionals` be a tuple with one field for each positional parameter. |
| 105 | 105 | ||
| 106 | The fields in `args` are typed. The type is based on the name of the value the parameter takes. | 106 | The fields in `args` and `psotionals` are typed. The type is based on the name of the value the |
| 107 | Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. | 107 | parameter takes. Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. |
| 108 | 108 | ||
| 109 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which | 109 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which |
| 110 | contains a parser that returns `usize`. You can pass in something other than | 110 | contains 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 | ||