summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2022-01-31 17:11:15 +0100
committerGravatar Jimmi Holst Christensen2022-01-31 17:11:15 +0100
commit7188a9fc85f6aa0f71a4cb7966f8b0a044f29e02 (patch)
tree0363b15fb5393c7ca46f60325eee93c13f9c76f7 /README.md
parentRelicense to MIT (diff)
downloadzig-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.md10
1 files changed, 6 insertions, 4 deletions
diff --git a/README.md b/README.md
index d872965..80d0e80 100644
--- a/README.md
+++ b/README.md
@@ -108,6 +108,7 @@ const std = @import("std");
108 108
109const debug = std.debug; 109const debug = std.debug;
110const io = std.io; 110const io = std.io;
111const process = std.process;
111 112
112pub fn main() !void { 113pub 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 = &params, 141 .params = &params,
140 .iter = &iter, 142 .iter = &iter,
141 .diagnostic = &diag, 143 .diagnostic = &diag,