summaryrefslogtreecommitdiff
path: root/clap.zig
diff options
context:
space:
mode:
Diffstat (limited to 'clap.zig')
-rw-r--r--clap.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/clap.zig b/clap.zig
index b603222..6054b24 100644
--- a/clap.zig
+++ b/clap.zig
@@ -18,6 +18,8 @@ test "clap" {
18 testing.refAllDecls(@This()); 18 testing.refAllDecls(@This());
19} 19}
20 20
21pub const default_assignment_separators = "=";
22
21/// The names a `Param` can have. 23/// The names a `Param` can have.
22pub const Names = struct { 24pub const Names = struct {
23 /// '-' prefix 25 /// '-' prefix
@@ -643,6 +645,7 @@ test "Diagnostic.report" {
643pub const ParseOptions = struct { 645pub const ParseOptions = struct {
644 allocator: mem.Allocator, 646 allocator: mem.Allocator,
645 diagnostic: ?*Diagnostic = null, 647 diagnostic: ?*Diagnostic = null,
648 assignment_separators: []const u8 = default_assignment_separators,
646}; 649};
647 650
648/// Same as `parseEx` but uses the `args.OsIterator` by default. 651/// Same as `parseEx` but uses the `args.OsIterator` by default.
@@ -662,6 +665,7 @@ pub fn parse(
662 // Let's reuse the arena from the `OSIterator` since we already have it. 665 // Let's reuse the arena from the `OSIterator` since we already have it.
663 .allocator = arena.allocator(), 666 .allocator = arena.allocator(),
664 .diagnostic = opt.diagnostic, 667 .diagnostic = opt.diagnostic,
668 .assignment_separators = opt.assignment_separators,
665 }); 669 });
666 670
667 return Result(Id, params, value_parsers){ 671 return Result(Id, params, value_parsers){
@@ -733,6 +737,7 @@ pub fn parseEx(
733 .params = params, 737 .params = params,
734 .iter = iter, 738 .iter = iter,
735 .diagnostic = opt.diagnostic, 739 .diagnostic = opt.diagnostic,
740 .assignment_separators = opt.assignment_separators,
736 }; 741 };
737 while (try stream.next()) |arg| { 742 while (try stream.next()) |arg| {
738 // TODO: We cannot use `try` inside the inline for because of a compiler bug that 743 // TODO: We cannot use `try` inside the inline for because of a compiler bug that
@@ -955,6 +960,24 @@ test "str and u64" {
955 defer res.deinit(); 960 defer res.deinit();
956} 961}
957 962
963test "different assignment separators" {
964 const params = comptime parseParamsComptime(
965 \\-a, --aa <usize>...
966 \\
967 );
968
969 var iter = args.SliceIterator{
970 .args = &.{ "-a=0", "--aa=1", "-a:2", "--aa:3" },
971 };
972 var res = try parseEx(Help, &params, parsers.default, &iter, .{
973 .allocator = testing.allocator,
974 .assignment_separators = "=:",
975 });
976 defer res.deinit();
977
978 try testing.expectEqualSlices(usize, &.{ 0, 1, 2, 3 }, res.args.aa);
979}
980
958test "everything" { 981test "everything" {
959 const params = comptime parseParamsComptime( 982 const params = comptime parseParamsComptime(
960 \\-a, --aa 983 \\-a, --aa