diff options
| author | 2019-06-12 15:30:30 +0200 | |
|---|---|---|
| committer | 2019-06-12 15:30:30 +0200 | |
| commit | 44ea38f25453fbf51de72505d7b3ddb0f3eec13c (patch) | |
| tree | 2ffd0fc94f65270f9f94edab940641b388ff3f16 /example | |
| parent | tried to fix travis (diff) | |
| download | zig-clap-44ea38f25453fbf51de72505d7b3ddb0f3eec13c.tar.gz zig-clap-44ea38f25453fbf51de72505d7b3ddb0f3eec13c.tar.xz zig-clap-44ea38f25453fbf51de72505d7b3ddb0f3eec13c.zip | |
updated to newest version of zig
Diffstat (limited to 'example')
| -rw-r--r-- | example/comptime-clap.zig | 24 | ||||
| -rw-r--r-- | example/streaming-clap.zig | 23 |
2 files changed, 32 insertions, 15 deletions
diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig index 8d2d8a8..935381f 100644 --- a/example/comptime-clap.zig +++ b/example/comptime-clap.zig | |||
| @@ -13,16 +13,20 @@ pub fn main() !void { | |||
| 13 | defer direct_allocator.deinit(); | 13 | defer direct_allocator.deinit(); |
| 14 | 14 | ||
| 15 | // First we specify what parameters our program can take. | 15 | // First we specify what parameters our program can take. |
| 16 | const params = comptime []clap.Param([]const u8){ | 16 | const params = comptime [_]clap.Param([]const u8){ |
| 17 | clap.Param([]const u8).flag( | 17 | clap.Param([]const u8){ |
| 18 | "Display this help and exit.", | 18 | .id = "Display this help and exit.", |
| 19 | clap.Names.both("help"), | 19 | .names = clap.Names{ .short = 'h', .long = "help" }, |
| 20 | ), | 20 | }, |
| 21 | clap.Param([]const u8).option( | 21 | clap.Param([]const u8){ |
| 22 | "An option parameter, which takes a value.", | 22 | .id = "An option parameter, which takes a value.", |
| 23 | clap.Names.both("number"), | 23 | .names = clap.Names{ .short = 'n', .long = "number" }, |
| 24 | ), | 24 | .takes_value = true, |
| 25 | clap.Param([]const u8).positional(""), | 25 | }, |
| 26 | clap.Param([]const u8){ | ||
| 27 | .id = "", | ||
| 28 | .takes_value = true, | ||
| 29 | }, | ||
| 26 | }; | 30 | }; |
| 27 | 31 | ||
| 28 | // We then initialize an argument iterator. We will use the OsIterator as it nicely | 32 | // We then initialize an argument iterator. We will use the OsIterator as it nicely |
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| { |