diff options
| author | 2018-03-14 15:01:00 +0100 | |
|---|---|---|
| committer | 2018-03-14 15:01:00 +0100 | |
| commit | e22a541c08edf0f2c2dffe5a9f3753fc78ca1964 (patch) | |
| tree | a2a3049e6a0c13cbe55ecc4099f4b64de59df8ad | |
| parent | Changed around some code in test (diff) | |
| download | zig-clap-e22a541c08edf0f2c2dffe5a9f3753fc78ca1964.tar.gz zig-clap-e22a541c08edf0f2c2dffe5a9f3753fc78ca1964.tar.xz zig-clap-e22a541c08edf0f2c2dffe5a9f3753fc78ca1964.zip | |
Fixed code crashing Zig
| -rw-r--r-- | clap.zig | 23 |
1 files changed, 11 insertions, 12 deletions
| @@ -98,7 +98,7 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default | |||
| 98 | var required = required_mask; | 98 | var required = required_mask; |
| 99 | 99 | ||
| 100 | var arg_i = usize(0); | 100 | var arg_i = usize(0); |
| 101 | loop: while (arg_i < args.len) : (arg_i += 1) { | 101 | while (arg_i < args.len) : (arg_i += 1) { |
| 102 | const pair = blk: { | 102 | const pair = blk: { |
| 103 | const tmp = args[arg_i]; | 103 | const tmp = args[arg_i]; |
| 104 | if (mem.startsWith(u8, tmp, "--")) | 104 | if (mem.startsWith(u8, tmp, "--")) |
| @@ -111,13 +111,12 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default | |||
| 111 | const arg = pair.arg; | 111 | const arg = pair.arg; |
| 112 | const kind = pair.kind; | 112 | const kind = pair.kind; |
| 113 | 113 | ||
| 114 | comptime var required_index : usize = 0; | 114 | var required_index : usize = 0; |
| 115 | inline_loop: inline for (options) |option, op_i| { | 115 | for (options) |option, op_i| { |
| 116 | |||
| 117 | switch (kind) { | 116 | switch (kind) { |
| 118 | Arg.Kind.None => { | 117 | Arg.Kind.None => { |
| 119 | if (option.short != null) continue :inline_loop; | 118 | if (option.short != null) continue; |
| 120 | if (option.long != null) continue :inline_loop; | 119 | if (option.long != null) continue; |
| 121 | 120 | ||
| 122 | try option.parser(&result, arg); | 121 | try option.parser(&result, arg); |
| 123 | 122 | ||
| @@ -133,15 +132,15 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default | |||
| 133 | else => {} | 132 | else => {} |
| 134 | } | 133 | } |
| 135 | 134 | ||
| 136 | continue :loop; | 135 | break; |
| 137 | }, | 136 | }, |
| 138 | Arg.Kind.Short => { | 137 | Arg.Kind.Short => { |
| 139 | const short = option.short ?? continue :inline_loop; | 138 | const short = option.short ?? continue; |
| 140 | if (arg.len != 1 or arg[0] != short) continue :inline_loop; | 139 | if (arg.len != 1 or arg[0] != short) continue; |
| 141 | }, | 140 | }, |
| 142 | Arg.Kind.Long => { | 141 | Arg.Kind.Long => { |
| 143 | const long = option.long ?? continue :inline_loop; | 142 | const long = option.long ?? continue; |
| 144 | if (!mem.eql(u8, long, arg)) continue :inline_loop; | 143 | if (!mem.eql(u8, long, arg)) continue; |
| 145 | } | 144 | } |
| 146 | } | 145 | } |
| 147 | 146 | ||
| @@ -161,7 +160,7 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default | |||
| 161 | else => {} | 160 | else => {} |
| 162 | } | 161 | } |
| 163 | 162 | ||
| 164 | continue :loop; | 163 | break; |
| 165 | } else { | 164 | } else { |
| 166 | return error.InvalidArgument; | 165 | return error.InvalidArgument; |
| 167 | } | 166 | } |