diff options
Diffstat (limited to 'example/streaming-clap.zig')
| -rw-r--r-- | example/streaming-clap.zig | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index f8d873d..41efd1f 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -2,25 +2,23 @@ const clap = @import("clap"); | |||
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | const debug = std.debug; | 4 | const debug = std.debug; |
| 5 | const io = std.io; | ||
| 5 | 6 | ||
| 6 | pub fn main() !void { | 7 | pub fn main() !void { |
| 7 | const allocator = std.heap.page_allocator; | 8 | const allocator = std.heap.page_allocator; |
| 8 | 9 | ||
| 9 | // First we specify what parameters our program can take. | 10 | // First we specify what parameters our program can take. |
| 10 | const params = [_]clap.Param(u8){ | 11 | const params = [_]clap.Param(u8){ |
| 11 | clap.Param(u8){ | 12 | .{ |
| 12 | .id = 'h', | 13 | .id = 'h', |
| 13 | .names = clap.Names{ .short = 'h', .long = "help" }, | 14 | .names = .{ .short = 'h', .long = "help" }, |
| 14 | }, | 15 | }, |
| 15 | clap.Param(u8){ | 16 | .{ |
| 16 | .id = 'n', | 17 | .id = 'n', |
| 17 | .names = clap.Names{ .short = 'n', .long = "number" }, | 18 | .names = .{ .short = 'n', .long = "number" }, |
| 18 | .takes_value = .One, | 19 | .takes_value = .one, |
| 19 | }, | ||
| 20 | clap.Param(u8){ | ||
| 21 | .id = 'f', | ||
| 22 | .takes_value = .One, | ||
| 23 | }, | 20 | }, |
| 21 | .{ .id = 'f', .takes_value = .one }, | ||
| 24 | }; | 22 | }; |
| 25 | 23 | ||
| 26 | // We then initialize an argument iterator. We will use the OsIterator as it nicely | 24 | // We then initialize an argument iterator. We will use the OsIterator as it nicely |
| @@ -41,7 +39,7 @@ pub fn main() !void { | |||
| 41 | // 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. |
| 42 | while (parser.next() catch |err| { | 40 | while (parser.next() catch |err| { |
| 43 | // Report useful error and exit | 41 | // Report useful error and exit |
| 44 | diag.report(std.io.getStdErr().outStream(), err) catch {}; | 42 | diag.report(io.getStdErr().writer(), err) catch {}; |
| 45 | return err; | 43 | return err; |
| 46 | }) |arg| { | 44 | }) |arg| { |
| 47 | // arg.param will point to the parameter which matched the argument. | 45 | // arg.param will point to the parameter which matched the argument. |