diff options
Diffstat (limited to 'clap.zig')
| -rw-r--r-- | clap.zig | 13 |
1 files changed, 10 insertions, 3 deletions
| @@ -162,11 +162,16 @@ pub fn Clap(comptime Result: type) type { | |||
| 162 | 162 | ||
| 163 | if (has_right_index) { | 163 | if (has_right_index) { |
| 164 | if (short_arg == short) { | 164 | if (short_arg == short) { |
| 165 | if (option.takes_value) |_| return error.OptionMissingValue; | 165 | if (option.takes_value) |parser| { |
| 166 | const value = arg[i + 1..]; | ||
| 167 | try parser.parse(&@field(result, option.field), value); | ||
| 168 | break :success; | ||
| 169 | } else { | ||
| 170 | @field(result, option.field) = true; | ||
| 171 | continue :short_arg_loop; | ||
| 172 | } | ||
| 166 | 173 | ||
| 167 | @field(result, option.field) = true; | ||
| 168 | required = newRequired(option, required, required_index); | 174 | required = newRequired(option, required, required_index); |
| 169 | continue :short_arg_loop; | ||
| 170 | } | 175 | } |
| 171 | } | 176 | } |
| 172 | } | 177 | } |
| @@ -420,10 +425,12 @@ test "clap.parse: short" { | |||
| 420 | testNoErr(clap, [][]const u8 { "-a" }, default.with("a", true)); | 425 | testNoErr(clap, [][]const u8 { "-a" }, default.with("a", true)); |
| 421 | testNoErr(clap, [][]const u8 { "-a", "-b" }, default.with("a", true).with("b", true)); | 426 | testNoErr(clap, [][]const u8 { "-a", "-b" }, default.with("a", true).with("b", true)); |
| 422 | testNoErr(clap, [][]const u8 { "-i=100" }, default.with("int", 100)); | 427 | testNoErr(clap, [][]const u8 { "-i=100" }, default.with("int", 100)); |
| 428 | testNoErr(clap, [][]const u8 { "-i100" }, default.with("int", 100)); | ||
| 423 | testNoErr(clap, [][]const u8 { "-i", "100" }, default.with("int", 100)); | 429 | testNoErr(clap, [][]const u8 { "-i", "100" }, default.with("int", 100)); |
| 424 | testNoErr(clap, [][]const u8 { "-ab" }, default.with("a", true).with("b", true)); | 430 | testNoErr(clap, [][]const u8 { "-ab" }, default.with("a", true).with("b", true)); |
| 425 | testNoErr(clap, [][]const u8 { "-abi", "100" }, default.with("a", true).with("b", true).with("int", 100)); | 431 | testNoErr(clap, [][]const u8 { "-abi", "100" }, default.with("a", true).with("b", true).with("int", 100)); |
| 426 | testNoErr(clap, [][]const u8 { "-abi=100" }, default.with("a", true).with("b", true).with("int", 100)); | 432 | testNoErr(clap, [][]const u8 { "-abi=100" }, default.with("a", true).with("b", true).with("int", 100)); |
| 433 | testNoErr(clap, [][]const u8 { "-abi100" }, default.with("a", true).with("b", true).with("int", 100)); | ||
| 427 | } | 434 | } |
| 428 | 435 | ||
| 429 | test "clap.parse: long" { | 436 | test "clap.parse: long" { |