diff options
| author | 2021-06-24 17:22:33 +0200 | |
|---|---|---|
| committer | 2021-06-24 17:22:33 +0200 | |
| commit | 9db6e56d1603a5fe738516b10a3b15b9209e4680 (patch) | |
| tree | b3d6c3ba7a27f37ebfa02a64a698ac13c62a545b /clap | |
| parent | parseParam: Set eval quota to std.math.maxInt(u32) (diff) | |
| download | zig-clap-9db6e56d1603a5fe738516b10a3b15b9209e4680.tar.gz zig-clap-9db6e56d1603a5fe738516b10a3b15b9209e4680.tar.xz zig-clap-9db6e56d1603a5fe738516b10a3b15b9209e4680.zip | |
Stay under 100 chars per line in all the code
Diffstat (limited to 'clap')
| -rw-r--r-- | clap/args.zig | 7 | ||||
| -rw-r--r-- | clap/comptime.zig | 3 | ||||
| -rw-r--r-- | clap/streaming.zig | 22 |
3 files changed, 24 insertions, 8 deletions
diff --git a/clap/args.zig b/clap/args.zig index 555e8ab..d848eb7 100644 --- a/clap/args.zig +++ b/clap/args.zig | |||
| @@ -252,7 +252,12 @@ pub const ShellIterator = struct { | |||
| 252 | } | 252 | } |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | fn result(iter: *ShellIterator, start: usize, end: usize, list: *std.ArrayList(u8)) Error!?[]const u8 { | 255 | fn result( |
| 256 | iter: *ShellIterator, | ||
| 257 | start: usize, | ||
| 258 | end: usize, | ||
| 259 | list: *std.ArrayList(u8), | ||
| 260 | ) Error!?[]const u8 { | ||
| 256 | const res = iter.str[start..end]; | 261 | const res = iter.str[start..end]; |
| 257 | 262 | ||
| 258 | // If we already have something in `list` that means that we could not | 263 | // If we already have something in `list` that means that we could not |
diff --git a/clap/comptime.zig b/clap/comptime.zig index 7808f52..cbc872e 100644 --- a/clap/comptime.zig +++ b/clap/comptime.zig | |||
| @@ -45,9 +45,8 @@ pub fn ComptimeClap( | |||
| 45 | pub fn parse(iter: anytype, opt: clap.ParseOptions) !@This() { | 45 | pub fn parse(iter: anytype, opt: clap.ParseOptions) !@This() { |
| 46 | const allocator = opt.allocator; | 46 | const allocator = opt.allocator; |
| 47 | var multis = [_]std.ArrayList([]const u8){undefined} ** multi_options; | 47 | var multis = [_]std.ArrayList([]const u8){undefined} ** multi_options; |
| 48 | for (multis) |*multi| { | 48 | for (multis) |*multi| |
| 49 | multi.* = std.ArrayList([]const u8).init(allocator); | 49 | multi.* = std.ArrayList([]const u8).init(allocator); |
| 50 | } | ||
| 51 | 50 | ||
| 52 | var pos = std.ArrayList([]const u8).init(allocator); | 51 | var pos = std.ArrayList([]const u8).init(allocator); |
| 53 | 52 | ||
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. |
| 26 | pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type { | 26 | pub 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 | ||
| 206 | fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, results: []const Arg(u8)) !void { | 206 | fn 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 | ||
| 228 | fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, expected: []const u8) !void { | 232 | fn 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(¶ms, &.{"-a=1"}, "The argument '-a' does not take a value\n"); | 428 | try testErr(¶ms, &.{"-a=1"}, "The argument '-a' does not take a value\n"); |
| 421 | try testErr(¶ms, &.{"--aa=1"}, "The argument '--aa' does not take a value\n"); | 429 | try testErr(¶ms, &.{"--aa=1"}, "The argument '--aa' does not take a value\n"); |
| 422 | try testErr(¶ms, &.{"-c"}, "The argument '-c' requires a value but none was supplied\n"); | 430 | try testErr(¶ms, &.{"-c"}, "The argument '-c' requires a value but none was supplied\n"); |
| 423 | try testErr(¶ms, &.{"--cc"}, "The argument '--cc' requires a value but none was supplied\n"); | 431 | try testErr( |
| 432 | ¶ms, | ||
| 433 | &.{"--cc"}, | ||
| 434 | "The argument '--cc' requires a value but none was supplied\n", | ||
| 435 | ); | ||
| 424 | } | 436 | } |