diff options
| author | 2022-01-31 17:11:15 +0100 | |
|---|---|---|
| committer | 2022-01-31 17:11:15 +0100 | |
| commit | 7188a9fc85f6aa0f71a4cb7966f8b0a044f29e02 (patch) | |
| tree | 0363b15fb5393c7ca46f60325eee93c13f9c76f7 /example/streaming-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 'example/streaming-clap.zig')
| -rw-r--r-- | example/streaming-clap.zig | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 9ed38dd..a7ab7d8 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -3,6 +3,7 @@ const std = @import("std"); | |||
| 3 | 3 | ||
| 4 | const debug = std.debug; | 4 | const debug = std.debug; |
| 5 | const io = std.io; | 5 | const io = std.io; |
| 6 | const process = std.process; | ||
| 6 | 7 | ||
| 7 | pub fn main() !void { | 8 | pub fn main() !void { |
| 8 | const allocator = std.heap.page_allocator; | 9 | const allocator = std.heap.page_allocator; |
| @@ -21,16 +22,17 @@ pub fn main() !void { | |||
| 21 | .{ .id = 'f', .takes_value = .one }, | 22 | .{ .id = 'f', .takes_value = .one }, |
| 22 | }; | 23 | }; |
| 23 | 24 | ||
| 24 | // We then initialize an argument iterator. We will use the OsIterator as it nicely | 25 | var iter = try process.ArgIterator.initWithAllocator(allocator); |
| 25 | // wraps iterating over arguments the most efficient way on each os. | ||
| 26 | var iter = try clap.args.OsIterator.init(allocator); | ||
| 27 | defer iter.deinit(); | 26 | defer iter.deinit(); |
| 28 | 27 | ||
| 28 | // Skip exe argument | ||
| 29 | _ = iter.next(); | ||
| 30 | |||
| 29 | // Initalize our diagnostics, which can be used for reporting useful errors. | 31 | // Initalize our diagnostics, which can be used for reporting useful errors. |
| 30 | // This is optional. You can also leave the `diagnostic` field unset if you | 32 | // This is optional. You can also leave the `diagnostic` field unset if you |
| 31 | // don't care about the extra information `Diagnostic` provides. | 33 | // don't care about the extra information `Diagnostic` provides. |
| 32 | var diag = clap.Diagnostic{}; | 34 | var diag = clap.Diagnostic{}; |
| 33 | var parser = clap.StreamingClap(u8, clap.args.OsIterator){ | 35 | var parser = clap.StreamingClap(u8, process.ArgIterator){ |
| 34 | .params = ¶ms, | 36 | .params = ¶ms, |
| 35 | .iter = &iter, | 37 | .iter = &iter, |
| 36 | .diagnostic = &diag, | 38 | .diagnostic = &diag, |