cli actions can be "+<name>"

This commit is contained in:
Mitchell Hashimoto
2023-09-15 12:17:59 -07:00
parent bcd88619c6
commit e11299a775

View File

@ -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);
}
}