summaryrefslogtreecommitdiff
path: root/example.zig
diff options
context:
space:
mode:
Diffstat (limited to 'example.zig')
-rw-r--r--example.zig73
1 files changed, 31 insertions, 42 deletions
diff --git a/example.zig b/example.zig
index 4d63b02..14b5487 100644
--- a/example.zig
+++ b/example.zig
@@ -1,12 +1,13 @@
1const std = @import("std"); 1const std = @import("std");
2const clap = @import("clap.zig"); 2const core = @import("core.zig");
3const clap = @import("extended.zig");
3 4
4const debug = std.debug; 5const debug = std.debug;
5const os = std.os; 6const os = std.os;
6 7
7const Clap = clap.Clap; 8const Clap = clap.Clap;
8const Command = clap.Command; 9const Param = clap.Param;
9const Argument = clap.Argument; 10const Parser = clap.Parser;
10 11
11const Options = struct { 12const Options = struct {
12 print_values: bool, 13 print_values: bool,
@@ -34,46 +35,34 @@ const Options = struct {
34// d = V=5 35// d = V=5
35 36
36pub fn main() !void { 37pub fn main() !void {
37 const parser = comptime Clap(Options).init( 38 const parser = comptime Clap(Options) {
38 Options { 39 .defaults = Options {
39 .print_values = false, 40 .print_values = false,
40 .a = 0, 41 .a = 0,
41 .b = 0, 42 .b = 0,
42 .c = 0, 43 .c = 0,
43 .d = "", 44 .d = "",
44 } 45 },
45 ) 46 .params = []Param {
46 .with("program_name", "My Test Command") 47 Param.init("a")
47 .with("author", "Hejsil") 48 .with("takes_value", Parser.int(i64, 10)),
48 .with("version", "v1") 49 Param.init("b")
49 .with("about", "Prints some values to the screen... Maybe.") 50 .with("takes_value", Parser.int(u64, 10)),
50 .with("command", Command.init("command") 51 Param.init("c")
51 .with("arguments", 52 .with("takes_value", Parser.int(u8, 10)),
52 []Argument { 53 Param.init("d")
53 Argument.arg("a") 54 .with("takes_value", Parser.string),
54 .with("help", "Set the a field of Option.") 55 Param.init("print_values")
55 .with("takes_value", clap.parse.int(i64, 10)), 56 .with("short", 'p')
56 Argument.arg("b") 57 .with("long", "print-values"),
57 .with("help", "Set the b field of Option.") 58 }
58 .with("takes_value", clap.parse.int(u64, 10)), 59 };
59 Argument.arg("c")
60 .with("help", "Set the c field of Option.")
61 .with("takes_value", clap.parse.int(u8, 10)),
62 Argument.arg("d")
63 .with("help", "Set the d field of Option.")
64 .with("takes_value", clap.parse.string),
65 Argument.field("print_values")
66 .with("help", "Print all not 0 values.")
67 .with("short", 'p')
68 .with("long", "print-values"),
69 }
70 )
71 );
72 60
73 const args = try os.argsAlloc(debug.global_allocator); 61 var arg_iter = core.OsArgIterator.init();
74 defer os.argsFree(debug.global_allocator, args); 62 const iter = &arg_iter.iter;
63 const command = iter.next(debug.global_allocator);
75 64
76 const options = try parser.parse(args[1..]); 65 const options = try parser.parse(debug.global_allocator, iter);
77 66
78 if (options.print_values) { 67 if (options.print_values) {
79 if (options.a != 0) debug.warn("a = {}\n", options.a); 68 if (options.a != 0) debug.warn("a = {}\n", options.a);