From 25e7072686cfa3b91df689bf5b76c6fb728003f6 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Fri, 27 Apr 2018 00:25:12 +0200 Subject: Short args can now take values directly after the arg * closes #5 --- clap.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'clap.zig') 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 { if (has_right_index) { if (short_arg == short) { - if (option.takes_value) |_| return error.OptionMissingValue; + if (option.takes_value) |parser| { + const value = arg[i + 1..]; + try parser.parse(&@field(result, option.field), value); + break :success; + } else { + @field(result, option.field) = true; + continue :short_arg_loop; + } - @field(result, option.field) = true; required = newRequired(option, required, required_index); - continue :short_arg_loop; } } } @@ -420,10 +425,12 @@ test "clap.parse: short" { testNoErr(clap, [][]const u8 { "-a" }, default.with("a", true)); testNoErr(clap, [][]const u8 { "-a", "-b" }, default.with("a", true).with("b", true)); testNoErr(clap, [][]const u8 { "-i=100" }, default.with("int", 100)); + testNoErr(clap, [][]const u8 { "-i100" }, default.with("int", 100)); testNoErr(clap, [][]const u8 { "-i", "100" }, default.with("int", 100)); testNoErr(clap, [][]const u8 { "-ab" }, default.with("a", true).with("b", true)); testNoErr(clap, [][]const u8 { "-abi", "100" }, default.with("a", true).with("b", true).with("int", 100)); testNoErr(clap, [][]const u8 { "-abi=100" }, default.with("a", true).with("b", true).with("int", 100)); + testNoErr(clap, [][]const u8 { "-abi100" }, default.with("a", true).with("b", true).with("int", 100)); } test "clap.parse: long" { -- cgit v1.2.3