summaryrefslogtreecommitdiff
path: root/clap.zig
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2018-04-27 00:25:12 +0200
committerGravatar Jimmi Holst Christensen2018-04-27 00:25:12 +0200
commit25e7072686cfa3b91df689bf5b76c6fb728003f6 (patch)
tree34684285a170012923726273ea3d5e970aa0d969 /clap.zig
parentAdded the ability to have argument have indexs (diff)
downloadzig-clap-25e7072686cfa3b91df689bf5b76c6fb728003f6.tar.gz
zig-clap-25e7072686cfa3b91df689bf5b76c6fb728003f6.tar.xz
zig-clap-25e7072686cfa3b91df689bf5b76c6fb728003f6.zip
Short args can now take values directly after the arg
* closes #5
Diffstat (limited to 'clap.zig')
-rw-r--r--clap.zig13
1 files changed, 10 insertions, 3 deletions
diff --git a/clap.zig b/clap.zig
index 3cd624e..269e9f1 100644
--- a/clap.zig
+++ b/clap.zig
@@ -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
429test "clap.parse: long" { 436test "clap.parse: long" {