diff options
| author | 2022-01-31 17:11:15 +0100 | |
|---|---|---|
| committer | 2022-01-31 17:11:15 +0100 | |
| commit | 7188a9fc85f6aa0f71a4cb7966f8b0a044f29e02 (patch) | |
| tree | 0363b15fb5393c7ca46f60325eee93c13f9c76f7 /clap.zig | |
| parent | Relicense to MIT (diff) | |
| download | zig-clap-7188a9fc85f6aa0f71a4cb7966f8b0a044f29e02.tar.gz zig-clap-7188a9fc85f6aa0f71a4cb7966f8b0a044f29e02.tar.xz zig-clap-7188a9fc85f6aa0f71a4cb7966f8b0a044f29e02.zip | |
Refactor the ArgIterator interface
They now follow the interface provided by the standard library. This now
means that we no longer needs `args.OsIterator` as that the one from
`std` can now be used directly.
Also remove `args.ShellIterator` as a simular iterator exists in `std`
called `ArgIteratorGeneral`.
Diffstat (limited to '')
| -rw-r--r-- | clap.zig | 14 |
1 files changed, 10 insertions, 4 deletions
| @@ -4,6 +4,7 @@ const debug = std.debug; | |||
| 4 | const heap = std.heap; | 4 | const heap = std.heap; |
| 5 | const io = std.io; | 5 | const io = std.io; |
| 6 | const mem = std.mem; | 6 | const mem = std.mem; |
| 7 | const process = std.process; | ||
| 7 | const testing = std.testing; | 8 | const testing = std.testing; |
| 8 | 9 | ||
| 9 | pub const args = @import("clap/args.zig"); | 10 | pub const args = @import("clap/args.zig"); |
| @@ -347,16 +348,21 @@ pub fn parse( | |||
| 347 | comptime params: []const Param(Id), | 348 | comptime params: []const Param(Id), |
| 348 | opt: ParseOptions, | 349 | opt: ParseOptions, |
| 349 | ) !Args(Id, params) { | 350 | ) !Args(Id, params) { |
| 350 | var iter = try args.OsIterator.init(opt.allocator); | 351 | var arena = heap.ArenaAllocator.init(opt.allocator); |
| 352 | errdefer arena.deinit(); | ||
| 353 | |||
| 354 | var iter = try process.ArgIterator.initWithAllocator(arena.allocator()); | ||
| 355 | const exe_arg = iter.next(); | ||
| 356 | |||
| 351 | const clap = try parseEx(Id, params, &iter, .{ | 357 | const clap = try parseEx(Id, params, &iter, .{ |
| 352 | // Let's reuse the arena from the `OSIterator` since we already have it. | 358 | // Let's reuse the arena from the `OSIterator` since we already have it. |
| 353 | .allocator = iter.arena.allocator(), | 359 | .allocator = arena.allocator(), |
| 354 | .diagnostic = opt.diagnostic, | 360 | .diagnostic = opt.diagnostic, |
| 355 | }); | 361 | }); |
| 356 | 362 | ||
| 357 | return Args(Id, params){ | 363 | return Args(Id, params){ |
| 358 | .exe_arg = iter.exe_arg, | 364 | .exe_arg = exe_arg, |
| 359 | .arena = iter.arena, | 365 | .arena = arena, |
| 360 | .clap = clap, | 366 | .clap = clap, |
| 361 | }; | 367 | }; |
| 362 | } | 368 | } |