summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jimmi HC2018-05-25 13:40:09 +0200
committerGravatar Jimmi HC2018-05-25 13:40:09 +0200
commit48ecac5b5a4a6f136bb8b38f5e9fe9b980579146 (patch)
tree95d4dc10af1b4a2205bad6ba4d52f48f2f0c0326
parentAdded support for accessing sub fields (diff)
downloadzig-clap-48ecac5b5a4a6f136bb8b38f5e9fe9b980579146.tar.gz
zig-clap-48ecac5b5a4a6f136bb8b38f5e9fe9b980579146.tar.xz
zig-clap-48ecac5b5a4a6f136bb8b38f5e9fe9b980579146.zip
Fixed code handling position
-rw-r--r--index.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/index.zig b/index.zig
index 7351515..02a7658 100644
--- a/index.zig
+++ b/index.zig
@@ -110,22 +110,22 @@ pub fn Clap(comptime Result: type) type {
110 var pos: usize = 0; 110 var pos: usize = 0;
111 var iter = core.Iterator(usize).init(core_params, arg_iter, allocator); 111 var iter = core.Iterator(usize).init(core_params, arg_iter, allocator);
112 defer iter.deinit(); 112 defer iter.deinit();
113
114 arg_loop:
113 while (try iter.next()) |arg| : (pos += 1) { 115 while (try iter.next()) |arg| : (pos += 1) {
114 inline for(clap.params) |param, i| { 116 inline for(clap.params) |param, i| {
115 if (arg.id == i) { 117 if (arg.id == i and (param.position ?? pos) == pos) {
116 if (param.position) |expected| {
117 if (expected != pos)
118 return error.InvalidPosition;
119 }
120
121 if (param.takes_value) |parser| { 118 if (param.takes_value) |parser| {
122 try parser.parse(getFieldPtr(&result, param.field), ??arg.value); 119 try parser.parse(getFieldPtr(&result, param.field), ??arg.value);
123 } else { 120 } else {
124 *getFieldPtr(&result, param.field) = true; 121 *getFieldPtr(&result, param.field) = true;
125 } 122 }
126 handled[i] = true; 123 handled[i] = true;
124 continue :arg_loop;
127 } 125 }
128 } 126 }
127
128 return error.InvalidArgument;
129 } 129 }
130 130
131 return result; 131 return result;
@@ -330,7 +330,7 @@ test "clap: position" {
330 }; 330 };
331 331
332 testNoErr(clap, [][]const u8 { "-a", "-b" }, default.with("a", true).with("b", true)); 332 testNoErr(clap, [][]const u8 { "-a", "-b" }, default.with("a", true).with("b", true));
333 testErr(clap, [][]const u8 { "-b", "-a" }, error.InvalidPosition); 333 testErr(clap, [][]const u8 { "-b", "-a" }, error.InvalidArgument);
334} 334}
335 335
336test "clap: sub fields" { 336test "clap: sub fields" {