diff options
| author | 2022-01-31 17:11:15 +0100 | |
|---|---|---|
| committer | 2022-01-31 17:11:15 +0100 | |
| commit | 7188a9fc85f6aa0f71a4cb7966f8b0a044f29e02 (patch) | |
| tree | 0363b15fb5393c7ca46f60325eee93c13f9c76f7 /README.md | |
| 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 'README.md')
| -rw-r--r-- | README.md | 10 |
1 files changed, 6 insertions, 4 deletions
| @@ -108,6 +108,7 @@ const std = @import("std"); | |||
| 108 | 108 | ||
| 109 | const debug = std.debug; | 109 | const debug = std.debug; |
| 110 | const io = std.io; | 110 | const io = std.io; |
| 111 | const process = std.process; | ||
| 111 | 112 | ||
| 112 | pub fn main() !void { | 113 | pub fn main() !void { |
| 113 | const allocator = std.heap.page_allocator; | 114 | const allocator = std.heap.page_allocator; |
| @@ -126,16 +127,17 @@ pub fn main() !void { | |||
| 126 | .{ .id = 'f', .takes_value = .one }, | 127 | .{ .id = 'f', .takes_value = .one }, |
| 127 | }; | 128 | }; |
| 128 | 129 | ||
| 129 | // We then initialize an argument iterator. We will use the OsIterator as it nicely | 130 | var iter = try process.ArgIterator.initWithAllocator(allocator); |
| 130 | // wraps iterating over arguments the most efficient way on each os. | ||
| 131 | var iter = try clap.args.OsIterator.init(allocator); | ||
| 132 | defer iter.deinit(); | 131 | defer iter.deinit(); |
| 133 | 132 | ||
| 133 | // Skip exe argument | ||
| 134 | _ = iter.next(); | ||
| 135 | |||
| 134 | // Initalize our diagnostics, which can be used for reporting useful errors. | 136 | // Initalize our diagnostics, which can be used for reporting useful errors. |
| 135 | // This is optional. You can also leave the `diagnostic` field unset if you | 137 | // This is optional. You can also leave the `diagnostic` field unset if you |
| 136 | // don't care about the extra information `Diagnostic` provides. | 138 | // don't care about the extra information `Diagnostic` provides. |
| 137 | var diag = clap.Diagnostic{}; | 139 | var diag = clap.Diagnostic{}; |
| 138 | var parser = clap.StreamingClap(u8, clap.args.OsIterator){ | 140 | var parser = clap.StreamingClap(u8, process.ArgIterator){ |
| 139 | .params = ¶ms, | 141 | .params = ¶ms, |
| 140 | .iter = &iter, | 142 | .iter = &iter, |
| 141 | .diagnostic = &diag, | 143 | .diagnostic = &diag, |