diff options
Diffstat (limited to '')
| -rw-r--r-- | example.zig | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/example.zig b/example.zig deleted file mode 100644 index 4b3fa82..0000000 --- a/example.zig +++ /dev/null | |||
| @@ -1,68 +0,0 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | const clap = @import("index.zig"); | ||
| 3 | |||
| 4 | const debug = std.debug; | ||
| 5 | const os = std.os; | ||
| 6 | |||
| 7 | const Options = struct { | ||
| 8 | print_values: bool, | ||
| 9 | a: i64, | ||
| 10 | b: u64, | ||
| 11 | c: u8, | ||
| 12 | d: []const u8, | ||
| 13 | }; | ||
| 14 | |||
| 15 | // Output on windows: | ||
| 16 | // zig-clap> .\example.exe -a 1 | ||
| 17 | // zig-clap> .\example.exe -p -a 1 | ||
| 18 | // a = 1 | ||
| 19 | // zig-clap> .\example.exe -pa 1 | ||
| 20 | // a = 1 | ||
| 21 | // zig-clap> .\example.exe -pd V1 | ||
| 22 | // d = V1 | ||
| 23 | // zig-clap> .\example.exe -pd=V2 | ||
| 24 | // d = V2 | ||
| 25 | // zig-clap> .\example.exe -p -d=V3 | ||
| 26 | // d = V3 | ||
| 27 | // zig-clap> .\example.exe -pdV=4 | ||
| 28 | // d = V=4 | ||
| 29 | // zig-clap> .\example.exe -p -dV=5 | ||
| 30 | // d = V=5 | ||
| 31 | |||
| 32 | pub fn main() !void { | ||
| 33 | const parser = comptime clap.Clap(Options) { | ||
| 34 | .defaults = Options { | ||
| 35 | .print_values = false, | ||
| 36 | .a = 0, | ||
| 37 | .b = 0, | ||
| 38 | .c = 0, | ||
| 39 | .d = "", | ||
| 40 | }, | ||
| 41 | .params = []clap.Param { | ||
| 42 | clap.Param.smart("a") | ||
| 43 | .with("takes_value", clap.Parser.int(i64, 10)), | ||
| 44 | clap.Param.smart("b") | ||
| 45 | .with("takes_value", clap.Parser.int(u64, 10)), | ||
| 46 | clap.Param.smart("c") | ||
| 47 | .with("takes_value", clap.Parser.int(u8, 10)), | ||
| 48 | clap.Param.smart("d") | ||
| 49 | .with("takes_value", clap.Parser.string), | ||
| 50 | clap.Param.smart("print_values") | ||
| 51 | .with("short", 'p') | ||
| 52 | .with("long", "print-values"), | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | |||
| 56 | var arg_iter = clap.core.OsArgIterator.init(); | ||
| 57 | const iter = &arg_iter.iter; | ||
| 58 | const command = iter.next(debug.global_allocator); | ||
| 59 | |||
| 60 | const options = try parser.parse(debug.global_allocator, iter); | ||
| 61 | |||
| 62 | if (options.print_values) { | ||
| 63 | if (options.a != 0) debug.warn("a = {}\n", options.a); | ||
| 64 | if (options.b != 0) debug.warn("b = {}\n", options.b); | ||
| 65 | if (options.c != 0) debug.warn("c = {}\n", options.c); | ||
| 66 | if (options.d.len != 0) debug.warn("d = {}\n", options.d); | ||
| 67 | } | ||
| 68 | } | ||