summaryrefslogtreecommitdiff
path: root/clap/streaming.zig
diff options
context:
space:
mode:
Diffstat (limited to 'clap/streaming.zig')
-rw-r--r--clap/streaming.zig22
1 files changed, 17 insertions, 5 deletions
diff --git a/clap/streaming.zig b/clap/streaming.zig
index e2f1311..885c581 100644
--- a/clap/streaming.zig
+++ b/clap/streaming.zig
@@ -21,8 +21,8 @@ pub fn Arg(comptime Id: type) type {
21} 21}
22 22
23/// A command line argument parser which, given an ArgIterator, will parse arguments according 23/// A command line argument parser which, given an ArgIterator, will parse arguments according
24/// to the params. StreamingClap parses in an iterating manner, so you have to use a loop together with 24/// to the params. StreamingClap parses in an iterating manner, so you have to use a loop
25/// StreamingClap.next to parse all the arguments of your program. 25/// together with StreamingClap.next to parse all the arguments of your program.
26pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type { 26pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type {
27 return struct { 27 return struct {
28 const State = union(enum) { 28 const State = union(enum) {
@@ -203,7 +203,11 @@ pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type {
203 }; 203 };
204} 204}
205 205
206fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, results: []const Arg(u8)) !void { 206fn testNoErr(
207 params: []const clap.Param(u8),
208 args_strings: []const []const u8,
209 results: []const Arg(u8),
210) !void {
207 var iter = args.SliceIterator{ .args = args_strings }; 211 var iter = args.SliceIterator{ .args = args_strings };
208 var c = StreamingClap(u8, args.SliceIterator){ 212 var c = StreamingClap(u8, args.SliceIterator){
209 .params = params, 213 .params = params,
@@ -225,7 +229,11 @@ fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, r
225 return error.TestFailed; 229 return error.TestFailed;
226} 230}
227 231
228fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, expected: []const u8) !void { 232fn testErr(
233 params: []const clap.Param(u8),
234 args_strings: []const []const u8,
235 expected: []const u8,
236) !void {
229 var diag: clap.Diagnostic = undefined; 237 var diag: clap.Diagnostic = undefined;
230 var iter = args.SliceIterator{ .args = args_strings }; 238 var iter = args.SliceIterator{ .args = args_strings };
231 var c = StreamingClap(u8, args.SliceIterator){ 239 var c = StreamingClap(u8, args.SliceIterator){
@@ -420,5 +428,9 @@ test "errors" {
420 try testErr(&params, &.{"-a=1"}, "The argument '-a' does not take a value\n"); 428 try testErr(&params, &.{"-a=1"}, "The argument '-a' does not take a value\n");
421 try testErr(&params, &.{"--aa=1"}, "The argument '--aa' does not take a value\n"); 429 try testErr(&params, &.{"--aa=1"}, "The argument '--aa' does not take a value\n");
422 try testErr(&params, &.{"-c"}, "The argument '-c' requires a value but none was supplied\n"); 430 try testErr(&params, &.{"-c"}, "The argument '-c' requires a value but none was supplied\n");
423 try testErr(&params, &.{"--cc"}, "The argument '--cc' requires a value but none was supplied\n"); 431 try testErr(
432 &params,
433 &.{"--cc"},
434 "The argument '--cc' requires a value but none was supplied\n",
435 );
424} 436}