diff options
Diffstat (limited to 'example/streaming-clap.zig')
| -rw-r--r-- | example/streaming-clap.zig | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index c58cd24..9d0a3ca 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | pub fn main() !void { | 1 | pub fn main() !void { |
| 2 | const allocator = std.heap.page_allocator; | 2 | var gpa_state = std.heap.DebugAllocator(.{}){}; |
| 3 | const gpa = gpa_state.allocator(); | ||
| 4 | defer _ = gpa_state.deinit(); | ||
| 5 | |||
| 6 | var threaded: std.Io.Threaded = .init_single_threaded; | ||
| 7 | const io: std.Io = threaded.io(); | ||
| 3 | 8 | ||
| 4 | // First we specify what parameters our program can take. | 9 | // First we specify what parameters our program can take. |
| 5 | const params = [_]clap.Param(u8){ | 10 | const params = [_]clap.Param(u8){ |
| @@ -15,7 +20,7 @@ pub fn main() !void { | |||
| 15 | .{ .id = 'f', .takes_value = .one }, | 20 | .{ .id = 'f', .takes_value = .one }, |
| 16 | }; | 21 | }; |
| 17 | 22 | ||
| 18 | var iter = try std.process.ArgIterator.initWithAllocator(allocator); | 23 | var iter = try std.process.ArgIterator.initWithAllocator(gpa); |
| 19 | defer iter.deinit(); | 24 | defer iter.deinit(); |
| 20 | 25 | ||
| 21 | // Skip exe argument. | 26 | // Skip exe argument. |
| @@ -31,9 +36,6 @@ pub fn main() !void { | |||
| 31 | .diagnostic = &diag, | 36 | .diagnostic = &diag, |
| 32 | }; | 37 | }; |
| 33 | 38 | ||
| 34 | var threaded: std.Io.Threaded = .init_single_threaded; | ||
| 35 | const io: std.Io = threaded.io(); | ||
| 36 | |||
| 37 | // Because we use a streaming parser, we have to consume each argument parsed individually. | 39 | // Because we use a streaming parser, we have to consume each argument parsed individually. |
| 38 | while (parser.next() catch |err| { | 40 | while (parser.next() catch |err| { |
| 39 | // Report useful error and exit. | 41 | // Report useful error and exit. |