diff options
| author | 2021-12-21 20:26:54 +0100 | |
|---|---|---|
| committer | 2021-12-21 20:26:54 +0100 | |
| commit | 285fb8f5cc604a3886450aba56b5e217760ab748 (patch) | |
| tree | 309601281c29395c5db521c5e5fa02c427dcb2d5 /clap | |
| parent | Improve help and usage examples (diff) | |
| parent | zig master updates: allocator changes (#60) (diff) | |
| download | zig-clap-285fb8f5cc604a3886450aba56b5e217760ab748.tar.gz zig-clap-285fb8f5cc604a3886450aba56b5e217760ab748.tar.xz zig-clap-285fb8f5cc604a3886450aba56b5e217760ab748.zip | |
Merge branch 'zig-master'
Diffstat (limited to 'clap')
| -rw-r--r-- | clap/args.zig | 10 | ||||
| -rw-r--r-- | clap/comptime.zig | 8 |
2 files changed, 9 insertions, 9 deletions
diff --git a/clap/args.zig b/clap/args.zig index a6be833..16299c8 100644 --- a/clap/args.zig +++ b/clap/args.zig | |||
| @@ -57,7 +57,7 @@ pub const OsIterator = struct { | |||
| 57 | /// return an error when we have no exe. | 57 | /// return an error when we have no exe. |
| 58 | exe_arg: ?[:0]const u8, | 58 | exe_arg: ?[:0]const u8, |
| 59 | 59 | ||
| 60 | pub fn init(allocator: *mem.Allocator) Error!OsIterator { | 60 | pub fn init(allocator: mem.Allocator) Error!OsIterator { |
| 61 | var res = OsIterator{ | 61 | var res = OsIterator{ |
| 62 | .arena = heap.ArenaAllocator.init(allocator), | 62 | .arena = heap.ArenaAllocator.init(allocator), |
| 63 | .args = process.args(), | 63 | .args = process.args(), |
| @@ -73,7 +73,7 @@ pub const OsIterator = struct { | |||
| 73 | 73 | ||
| 74 | pub fn next(iter: *OsIterator) Error!?[:0]const u8 { | 74 | pub fn next(iter: *OsIterator) Error!?[:0]const u8 { |
| 75 | if (builtin.os.tag == .windows) { | 75 | if (builtin.os.tag == .windows) { |
| 76 | return try iter.args.next(&iter.arena.allocator) orelse return null; | 76 | return try iter.args.next(iter.arena.allocator()) orelse return null; |
| 77 | } else { | 77 | } else { |
| 78 | return iter.args.nextPosix(); | 78 | return iter.args.nextPosix(); |
| 79 | } | 79 | } |
| @@ -91,7 +91,7 @@ pub const ShellIterator = struct { | |||
| 91 | arena: heap.ArenaAllocator, | 91 | arena: heap.ArenaAllocator, |
| 92 | str: []const u8, | 92 | str: []const u8, |
| 93 | 93 | ||
| 94 | pub fn init(allocator: *mem.Allocator, str: []const u8) ShellIterator { | 94 | pub fn init(allocator: mem.Allocator, str: []const u8) ShellIterator { |
| 95 | return .{ | 95 | return .{ |
| 96 | .arena = heap.ArenaAllocator.init(allocator), | 96 | .arena = heap.ArenaAllocator.init(allocator), |
| 97 | .str = str, | 97 | .str = str, |
| @@ -106,7 +106,7 @@ pub const ShellIterator = struct { | |||
| 106 | // Whenever possible, this iterator will return slices into `str` instead of | 106 | // Whenever possible, this iterator will return slices into `str` instead of |
| 107 | // allocating. Sometimes this is not possible, for example, escaped characters | 107 | // allocating. Sometimes this is not possible, for example, escaped characters |
| 108 | // have be be unescape, so we need to allocate in this case. | 108 | // have be be unescape, so we need to allocate in this case. |
| 109 | var list = std.ArrayList(u8).init(&iter.arena.allocator); | 109 | var list = std.ArrayList(u8).init(iter.arena.allocator()); |
| 110 | var start: usize = 0; | 110 | var start: usize = 0; |
| 111 | var state: enum { | 111 | var state: enum { |
| 112 | skip_whitespace, | 112 | skip_whitespace, |
| @@ -274,7 +274,7 @@ pub const ShellIterator = struct { | |||
| 274 | 274 | ||
| 275 | fn testShellIteratorOk(str: []const u8, allocations: usize, expect: []const []const u8) !void { | 275 | fn testShellIteratorOk(str: []const u8, allocations: usize, expect: []const []const u8) !void { |
| 276 | var allocator = testing.FailingAllocator.init(testing.allocator, allocations); | 276 | var allocator = testing.FailingAllocator.init(testing.allocator, allocations); |
| 277 | var it = ShellIterator.init(&allocator.allocator, str); | 277 | var it = ShellIterator.init(allocator.allocator(), str); |
| 278 | defer it.deinit(); | 278 | defer it.deinit(); |
| 279 | 279 | ||
| 280 | for (expect) |e| { | 280 | for (expect) |e| { |
diff --git a/clap/comptime.zig b/clap/comptime.zig index a0f57ad..b440004 100644 --- a/clap/comptime.zig +++ b/clap/comptime.zig | |||
| @@ -41,7 +41,7 @@ pub fn ComptimeClap( | |||
| 41 | single_options_is_set: std.PackedIntArray(u1, single_options), | 41 | single_options_is_set: std.PackedIntArray(u1, single_options), |
| 42 | flags: std.PackedIntArray(u1, flags), | 42 | flags: std.PackedIntArray(u1, flags), |
| 43 | pos: []const []const u8, | 43 | pos: []const []const u8, |
| 44 | allocator: *mem.Allocator, | 44 | allocator: mem.Allocator, |
| 45 | 45 | ||
| 46 | pub fn parse(iter: anytype, opt: clap.ParseOptions) !@This() { | 46 | pub fn parse(iter: anytype, opt: clap.ParseOptions) !@This() { |
| 47 | const allocator = opt.allocator; | 47 | const allocator = opt.allocator; |
| @@ -82,8 +82,8 @@ pub fn ComptimeClap( | |||
| 82 | if (multis.len != 0) | 82 | if (multis.len != 0) |
| 83 | try multis[param.id].append(arg.value.?); | 83 | try multis[param.id].append(arg.value.?); |
| 84 | } else { | 84 | } else { |
| 85 | debug.assert(res.flags.len() != 0); | 85 | debug.assert(res.flags.len != 0); |
| 86 | if (res.flags.len() != 0) | 86 | if (res.flags.len != 0) |
| 87 | res.flags.set(param.id, 1); | 87 | res.flags.set(param.id, 1); |
| 88 | } | 88 | } |
| 89 | } | 89 | } |
| @@ -195,7 +195,7 @@ fn testErr( | |||
| 195 | ) !void { | 195 | ) !void { |
| 196 | var diag = clap.Diagnostic{}; | 196 | var diag = clap.Diagnostic{}; |
| 197 | var iter = clap.args.SliceIterator{ .args = args_strings }; | 197 | var iter = clap.args.SliceIterator{ .args = args_strings }; |
| 198 | var args = clap.parseEx(u8, params, &iter, .{ | 198 | _ = clap.parseEx(u8, params, &iter, .{ |
| 199 | .allocator = testing.allocator, | 199 | .allocator = testing.allocator, |
| 200 | .diagnostic = &diag, | 200 | .diagnostic = &diag, |
| 201 | }) catch |err| { | 201 | }) catch |err| { |