diff options
| author | 2018-06-01 08:37:50 +0200 | |
|---|---|---|
| committer | 2018-06-01 08:37:50 +0200 | |
| commit | 8ff2b3ff8313b260b07115b8a773e40b5c0194c6 (patch) | |
| tree | 97dc5b5b95f7a5ad8a72b8989b5cee49fffb8992 | |
| parent | Core args now have a pointer to the param that the arg belongs to (diff) | |
| download | zig-clap-8ff2b3ff8313b260b07115b8a773e40b5c0194c6.tar.gz zig-clap-8ff2b3ff8313b260b07115b8a773e40b5c0194c6.tar.xz zig-clap-8ff2b3ff8313b260b07115b8a773e40b5c0194c6.zip | |
Id is now gotten through param of arg
| -rw-r--r-- | src/extended.zig | 4 | ||||
| -rw-r--r-- | tests/core.zig | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/extended.zig b/src/extended.zig index 9427b83..b94f6f5 100644 --- a/src/extended.zig +++ b/src/extended.zig | |||
| @@ -167,7 +167,7 @@ pub const Command = struct { | |||
| 167 | inline for(command.params) |param, i| { | 167 | inline for(command.params) |param, i| { |
| 168 | comptime const field = "result." ++ param.field; | 168 | comptime const field = "result." ++ param.field; |
| 169 | 169 | ||
| 170 | if (arg.id == i and (param.position ?? pos) == pos) { | 170 | if (arg.param.id == i and (param.position ?? pos) == pos) { |
| 171 | if (param.takes_value) |parser| { | 171 | if (param.takes_value) |parser| { |
| 172 | try parser.parse(getFieldPtr(&result, field), ??arg.value); | 172 | try parser.parse(getFieldPtr(&result, field), ??arg.value); |
| 173 | } else { | 173 | } else { |
| @@ -183,7 +183,7 @@ pub const Command = struct { | |||
| 183 | comptime var sub_command = c; | 183 | comptime var sub_command = c; |
| 184 | sub_command.parent = command; | 184 | sub_command.parent = command; |
| 185 | 185 | ||
| 186 | if (arg.id == i + command.params.len) { | 186 | if (arg.param.id == i + command.params.len) { |
| 187 | getFieldPtr(&result, field).* = try sub_command.parseHelper(&result, allocator, arg_iter); | 187 | getFieldPtr(&result, field).* = try sub_command.parseHelper(&result, allocator, arg_iter); |
| 188 | continue :arg_loop; | 188 | continue :arg_loop; |
| 189 | } | 189 | } |
diff --git a/tests/core.zig b/tests/core.zig index a6a705e..d4304a1 100644 --- a/tests/core.zig +++ b/tests/core.zig | |||
| @@ -18,7 +18,7 @@ fn testNoErr(params: []const Param(u8), args: []const []const u8, ids: []const u | |||
| 18 | 18 | ||
| 19 | var i: usize = 0; | 19 | var i: usize = 0; |
| 20 | while (iter.next() catch unreachable) |arg| : (i += 1) { | 20 | while (iter.next() catch unreachable) |arg| : (i += 1) { |
| 21 | debug.assert(ids[i] == arg.id); | 21 | debug.assert(ids[i] == arg.param.id); |
| 22 | const expected_value = values[i] ?? { | 22 | const expected_value = values[i] ?? { |
| 23 | debug.assert(arg.value == null); | 23 | debug.assert(arg.value == null); |
| 24 | continue; | 24 | continue; |