From e11299a7752b7f7a5526d0e8bd76766b34481c73 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 15 Sep 2023 12:17:59 -0700 Subject: [PATCH] cli actions can be "+" --- src/cli_action.zig | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/cli_action.zig b/src/cli_action.zig index 095770b56..d852c243f 100644 --- a/src/cli_action.zig +++ b/src/cli_action.zig @@ -40,7 +40,7 @@ pub const Action = enum { pending = std.meta.stringToEnum(Action, arg[1..]) orelse return Error.InvalidAction; } - return null; + return pending; } /// Run the action. This returns the exit code to exit with. @@ -105,3 +105,38 @@ test "parse action version" { try testing.expect(action.? == .version); } } + +test "parse action plus" { + const testing = std.testing; + const alloc = testing.allocator; + + { + var iter = try std.process.ArgIteratorGeneral(.{}).init( + alloc, + "--a=42 --b --b-f=false +version", + ); + defer iter.deinit(); + const action = try Action.detectIter(&iter); + try testing.expect(action.? == .version); + } + + { + var iter = try std.process.ArgIteratorGeneral(.{}).init( + alloc, + "+version --a=42 --b --b-f=false", + ); + defer iter.deinit(); + const action = try Action.detectIter(&iter); + try testing.expect(action.? == .version); + } + + { + var iter = try std.process.ArgIteratorGeneral(.{}).init( + alloc, + "--c=84 --d +version --a=42 --b --b-f=false", + ); + defer iter.deinit(); + const action = try Action.detectIter(&iter); + try testing.expect(action.? == .version); + } +}