summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2019-01-17 15:52:45 +0100
committerGravatar Jimmi Holst Christensen2019-01-17 15:52:45 +0100
commit938b3ff7787a3e99bc41cac9add5ff25835eee22 (patch)
treeefefe7cd2d0cbaebdb664de37848a5ad01a87fef /example
parentRenamed helpEx to helpFull and added a new helpEx that wraps helpFull (diff)
downloadzig-clap-938b3ff7787a3e99bc41cac9add5ff25835eee22.tar.gz
zig-clap-938b3ff7787a3e99bc41cac9add5ff25835eee22.tar.xz
zig-clap-938b3ff7787a3e99bc41cac9add5ff25835eee22.zip
Refactored the arg iterators to new be static interface implementations
* This makes arg iterators easier to understand and implement * It should also be faster than using the fieldToParent builtin
Diffstat (limited to 'example')
-rw-r--r--example/comptime-clap.zig7
-rw-r--r--example/streaming-clap.zig7
2 files changed, 6 insertions, 8 deletions
diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig
index b275dc7..8517db8 100644
--- a/example/comptime-clap.zig
+++ b/example/comptime-clap.zig
@@ -27,15 +27,14 @@ pub fn main() !void {
27 27
28 // We then initialize an argument iterator. We will use the OsIterator as it nicely 28 // We then initialize an argument iterator. We will use the OsIterator as it nicely
29 // wraps iterating over arguments the most efficient way on each os. 29 // wraps iterating over arguments the most efficient way on each os.
30 var os_iter = clap.args.OsIterator.init(allocator); 30 var iter = clap.args.OsIterator.init(allocator);
31 const iter = &os_iter.iter; 31 defer iter.deinit();
32 defer os_iter.deinit();
33 32
34 // Consume the exe arg. 33 // Consume the exe arg.
35 const exe = try iter.next(); 34 const exe = try iter.next();
36 35
37 // Finally we can parse the arguments 36 // Finally we can parse the arguments
38 var args = try clap.ComptimeClap([]const u8, params).parse(allocator, clap.args.OsIterator.Error, iter); 37 var args = try clap.ComptimeClap([]const u8, params).parse(allocator, clap.args.OsIterator, &iter);
39 defer args.deinit(); 38 defer args.deinit();
40 39
41 // clap.help is a function that can print a simple help message, given a 40 // clap.help is a function that can print a simple help message, given a
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig
index 57ebe71..a52a222 100644
--- a/example/streaming-clap.zig
+++ b/example/streaming-clap.zig
@@ -17,15 +17,14 @@ pub fn main() !void {
17 17
18 // We then initialize an argument iterator. We will use the OsIterator as it nicely 18 // We then initialize an argument iterator. We will use the OsIterator as it nicely
19 // wraps iterating over arguments the most efficient way on each os. 19 // wraps iterating over arguments the most efficient way on each os.
20 var os_iter = clap.args.OsIterator.init(allocator); 20 var iter = clap.args.OsIterator.init(allocator);
21 const iter = &os_iter.iter; 21 defer iter.deinit();
22 defer os_iter.deinit();
23 22
24 // Consume the exe arg. 23 // Consume the exe arg.
25 const exe = try iter.next(); 24 const exe = try iter.next();
26 25
27 // Finally we initialize our streaming parser. 26 // Finally we initialize our streaming parser.
28 var parser = clap.StreamingClap(u8, clap.args.OsIterator.Error).init(params, iter); 27 var parser = clap.StreamingClap(u8, clap.args.OsIterator).init(params, &iter);
29 28
30 // Because we use a streaming parser, we have to consume each argument parsed individually. 29 // Because we use a streaming parser, we have to consume each argument parsed individually.
31 while (try parser.next()) |arg| { 30 while (try parser.next()) |arg| {