diff options
Diffstat (limited to '')
| -rw-r--r-- | example/streaming-clap.zig | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index aad3e71..71a2fca 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -9,10 +9,20 @@ pub fn main() !void { | |||
| 9 | defer direct_allocator.deinit(); | 9 | defer direct_allocator.deinit(); |
| 10 | 10 | ||
| 11 | // First we specify what parameters our program can take. | 11 | // First we specify what parameters our program can take. |
| 12 | const params = []clap.Param(u8){ | 12 | const params = [_]clap.Param(u8){ |
| 13 | clap.Param(u8).flag('h', clap.Names.both("help")), | 13 | clap.Param(u8){ |
| 14 | clap.Param(u8).option('n', clap.Names.both("number")), | 14 | .id = 'h', |
| 15 | clap.Param(u8).positional('f'), | 15 | .names = clap.Names{ .short = 'h', .long = "help" }, |
| 16 | }, | ||
| 17 | clap.Param(u8){ | ||
| 18 | .id = 'n', | ||
| 19 | .names = clap.Names{ .short = 'n', .long = "number" }, | ||
| 20 | .takes_value = true, | ||
| 21 | }, | ||
| 22 | clap.Param(u8){ | ||
| 23 | .id = 'f', | ||
| 24 | .takes_value = true, | ||
| 25 | }, | ||
| 16 | }; | 26 | }; |
| 17 | 27 | ||
| 18 | // 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 |
| @@ -24,7 +34,10 @@ pub fn main() !void { | |||
| 24 | const exe = try iter.next(); | 34 | const exe = try iter.next(); |
| 25 | 35 | ||
| 26 | // Finally we initialize our streaming parser. | 36 | // Finally we initialize our streaming parser. |
| 27 | var parser = clap.StreamingClap(u8, clap.args.OsIterator).init(params, &iter); | 37 | var parser = clap.StreamingClap(u8, clap.args.OsIterator){ |
| 38 | .params = params, | ||
| 39 | .iter = &iter, | ||
| 40 | }; | ||
| 28 | 41 | ||
| 29 | // Because we use a streaming parser, we have to consume each argument parsed individually. | 42 | // Because we use a streaming parser, we have to consume each argument parsed individually. |
| 30 | while (try parser.next()) |arg| { | 43 | while (try parser.next()) |arg| { |