diff options
| author | 2020-08-28 15:57:36 +1000 | |
|---|---|---|
| committer | 2020-09-06 17:31:27 +0200 | |
| commit | 41ac75b6db818ce9431d145d5a9e335cf38cc117 (patch) | |
| tree | 4c33df98bd1e9e562b73885cd0d1256e84345eb7 | |
| parent | add documentation to Values enum (diff) | |
| download | zig-clap-41ac75b6db818ce9431d145d5a9e335cf38cc117.tar.gz zig-clap-41ac75b6db818ce9431d145d5a9e335cf38cc117.tar.xz zig-clap-41ac75b6db818ce9431d145d5a9e335cf38cc117.zip | |
fix up
| -rw-r--r-- | clap.zig | 4 | ||||
| -rw-r--r-- | clap/comptime.zig | 13 |
2 files changed, 10 insertions, 7 deletions
| @@ -277,8 +277,8 @@ pub fn Args(comptime Id: type, comptime params: []const Param(Id)) type { | |||
| 277 | return a.clap.option(name); | 277 | return a.clap.option(name); |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | pub fn allOptions(a: @This(), comptime name: []const u8) [][]const u8 { | 280 | pub fn options(a: @This(), comptime name: []const u8) []const []const u8 { |
| 281 | return a.clap.allOptions(name); | 281 | return a.clap.options(name); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | pub fn positionals(a: @This()) []const []const u8 { | 284 | pub fn positionals(a: @This()) []const []const u8 { |
diff --git a/clap/comptime.zig b/clap/comptime.zig index edbaafb..99f0be6 100644 --- a/clap/comptime.zig +++ b/clap/comptime.zig | |||
| @@ -39,7 +39,7 @@ pub fn ComptimeClap(comptime Id: type, comptime params: []const clap.Param(Id)) | |||
| 39 | allocator: *mem.Allocator, | 39 | allocator: *mem.Allocator, |
| 40 | 40 | ||
| 41 | pub fn parse(allocator: *mem.Allocator, comptime ArgIter: type, iter: *ArgIter) !@This() { | 41 | pub fn parse(allocator: *mem.Allocator, comptime ArgIter: type, iter: *ArgIter) !@This() { |
| 42 | var multis = [_]std.ArrayList([]const u8){undefined} ** single_options; | 42 | var multis = [_]std.ArrayList([]const u8){undefined} ** multi_options; |
| 43 | for (multis) |*multi| { | 43 | for (multis) |*multi| { |
| 44 | multi.* = std.ArrayList([]const u8).init(allocator); | 44 | multi.* = std.ArrayList([]const u8).init(allocator); |
| 45 | } | 45 | } |
| @@ -64,13 +64,16 @@ pub fn ComptimeClap(comptime Id: type, comptime params: []const clap.Param(Id)) | |||
| 64 | try pos.append(arg.value.?); | 64 | try pos.append(arg.value.?); |
| 65 | } else if (param.takes_value == .One) { | 65 | } else if (param.takes_value == .One) { |
| 66 | debug.assert(res.single_options.len != 0); | 66 | debug.assert(res.single_options.len != 0); |
| 67 | res.single_options[param.id] = arg.value.?; | 67 | if (res.single_options.len != 0) |
| 68 | res.single_options[param.id] = arg.value.?; | ||
| 68 | } else if (param.takes_value == .Many) { | 69 | } else if (param.takes_value == .Many) { |
| 69 | debug.assert(res.multi_options.len != 0); | 70 | debug.assert(multis.len != 0); |
| 70 | try multis[param.id].append(arg.value.?); | 71 | if (multis.len != 0) |
| 72 | try multis[param.id].append(arg.value.?); | ||
| 71 | } else { | 73 | } else { |
| 72 | debug.assert(res.flags.len != 0); | 74 | debug.assert(res.flags.len != 0); |
| 73 | res.flags[param.id] = true; | 75 | if (res.flags.len != 0) |
| 76 | res.flags[param.id] = true; | ||
| 74 | } | 77 | } |
| 75 | } | 78 | } |
| 76 | 79 | ||