diff options
Diffstat (limited to 'example/streaming-clap.zig')
| -rw-r--r-- | example/streaming-clap.zig | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 9d0a3ca..8198913 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -1,11 +1,4 @@ | |||
| 1 | pub fn main() !void { | 1 | pub fn main(init: std.process.Init) !void { |
| 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(); | ||
| 8 | |||
| 9 | // First we specify what parameters our program can take. | 2 | // First we specify what parameters our program can take. |
| 10 | const params = [_]clap.Param(u8){ | 3 | const params = [_]clap.Param(u8){ |
| 11 | .{ | 4 | .{ |
| @@ -20,7 +13,7 @@ pub fn main() !void { | |||
| 20 | .{ .id = 'f', .takes_value = .one }, | 13 | .{ .id = 'f', .takes_value = .one }, |
| 21 | }; | 14 | }; |
| 22 | 15 | ||
| 23 | var iter = try std.process.ArgIterator.initWithAllocator(gpa); | 16 | var iter = try init.minimal.args.iterateAllocator(init.gpa); |
| 24 | defer iter.deinit(); | 17 | defer iter.deinit(); |
| 25 | 18 | ||
| 26 | // Skip exe argument. | 19 | // Skip exe argument. |
| @@ -30,7 +23,7 @@ pub fn main() !void { | |||
| 30 | // This is optional. You can also leave the `diagnostic` field unset if you | 23 | // This is optional. You can also leave the `diagnostic` field unset if you |
| 31 | // don't care about the extra information `Diagnostic` provides. | 24 | // don't care about the extra information `Diagnostic` provides. |
| 32 | var diag = clap.Diagnostic{}; | 25 | var diag = clap.Diagnostic{}; |
| 33 | var parser = clap.streaming.Clap(u8, std.process.ArgIterator){ | 26 | var parser = clap.streaming.Clap(u8, std.process.Args.Iterator){ |
| 34 | .params = ¶ms, | 27 | .params = ¶ms, |
| 35 | .iter = &iter, | 28 | .iter = &iter, |
| 36 | .diagnostic = &diag, | 29 | .diagnostic = &diag, |
| @@ -39,7 +32,7 @@ pub fn main() !void { | |||
| 39 | // Because we use a streaming parser, we have to consume each argument parsed individually. | 32 | // Because we use a streaming parser, we have to consume each argument parsed individually. |
| 40 | while (parser.next() catch |err| { | 33 | while (parser.next() catch |err| { |
| 41 | // Report useful error and exit. | 34 | // Report useful error and exit. |
| 42 | try diag.reportToFile(io, .stderr(), err); | 35 | try diag.reportToFile(init.io, .stderr(), err); |
| 43 | return err; | 36 | return err; |
| 44 | }) |arg| { | 37 | }) |arg| { |
| 45 | // arg.param will point to the parameter which matched the argument. | 38 | // arg.param will point to the parameter which matched the argument. |