diff options
| author | 2024-10-24 15:36:55 +0200 | |
|---|---|---|
| committer | 2024-10-24 16:35:47 +0200 | |
| commit | 4e293092fc56ebf46d9c17e4e203ca54c63a0b09 (patch) | |
| tree | fc400c62cb7f96f0cc475162c7084dadb1f3b029 /example | |
| 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 'example')
| -rw-r--r-- | example/README.md.template | 6 | ||||
| -rw-r--r-- | example/simple-ex.zig | 2 | ||||
| -rw-r--r-- | example/simple.zig | 2 |
3 files changed, 5 insertions, 5 deletions
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. | |||
| 61 | 61 | ||
| 62 | The result will contain an `args` field and a `positionals` field. `args` will have one field | 62 | The result will contain an `args` field and a `positionals` field. `args` will have one field |
| 63 | for each none positional parameter of your program. The name of the field will be the longest | 63 | for each none positional parameter of your program. The name of the field will be the longest |
| 64 | name of the parameter. | 64 | name of the parameter. `positionals` be a tuple with one field for each positional parameter. |
| 65 | 65 | ||
| 66 | The fields in `args` are typed. The type is based on the name of the value the parameter takes. | 66 | The fields in `args` and `psotionals` are typed. The type is based on the name of the value the |
| 67 | Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. | 67 | parameter takes. Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. |
| 68 | 68 | ||
| 69 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which | 69 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which |
| 70 | contains a parser that returns `usize`. You can pass in something other than | 70 | 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 { | |||
| 44 | std.debug.print("--answer = {s}\n", .{@tagName(a)}); | 44 | std.debug.print("--answer = {s}\n", .{@tagName(a)}); |
| 45 | for (res.args.string) |s| | 45 | for (res.args.string) |s| |
| 46 | std.debug.print("--string = {s}\n", .{s}); | 46 | std.debug.print("--string = {s}\n", .{s}); |
| 47 | for (res.positionals) |pos| | 47 | for (res.positionals[0]) |pos| |
| 48 | std.debug.print("{s}\n", .{pos}); | 48 | std.debug.print("{s}\n", .{pos}); |
| 49 | } | 49 | } |
| 50 | 50 | ||
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 { | |||
| 32 | std.debug.print("--number = {}\n", .{n}); | 32 | std.debug.print("--number = {}\n", .{n}); |
| 33 | for (res.args.string) |s| | 33 | for (res.args.string) |s| |
| 34 | std.debug.print("--string = {s}\n", .{s}); | 34 | std.debug.print("--string = {s}\n", .{s}); |
| 35 | for (res.positionals) |pos| | 35 | for (res.positionals[0]) |pos| |
| 36 | std.debug.print("{s}\n", .{pos}); | 36 | std.debug.print("{s}\n", .{pos}); |
| 37 | } | 37 | } |
| 38 | 38 | ||