summaryrefslogtreecommitdiff
path: root/example.zig
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2018-05-20 12:51:43 +0200
committerGravatar Jimmi Holst Christensen2018-05-20 12:51:43 +0200
commit661d32ded068ecff486a952626bd209240035781 (patch)
treef2f10528cd2b98bc8ea5b193da54577da094e3bf /example.zig
parentRemoved false or none tested advertisement from README (diff)
downloadzig-clap-661d32ded068ecff486a952626bd209240035781.tar.gz
zig-clap-661d32ded068ecff486a952626bd209240035781.tar.xz
zig-clap-661d32ded068ecff486a952626bd209240035781.zip
Support for command params in core.zig
* Also refactored structure * related: #1
Diffstat (limited to 'example.zig')
-rw-r--r--example.zig31
1 files changed, 13 insertions, 18 deletions
diff --git a/example.zig b/example.zig
index 14b5487..4b3fa82 100644
--- a/example.zig
+++ b/example.zig
@@ -1,14 +1,9 @@
1const std = @import("std"); 1const std = @import("std");
2const core = @import("core.zig"); 2const clap = @import("index.zig");
3const clap = @import("extended.zig");
4 3
5const debug = std.debug; 4const debug = std.debug;
6const os = std.os; 5const os = std.os;
7 6
8const Clap = clap.Clap;
9const Param = clap.Param;
10const Parser = clap.Parser;
11
12const Options = struct { 7const Options = struct {
13 print_values: bool, 8 print_values: bool,
14 a: i64, 9 a: i64,
@@ -35,7 +30,7 @@ const Options = struct {
35// d = V=5 30// d = V=5
36 31
37pub fn main() !void { 32pub fn main() !void {
38 const parser = comptime Clap(Options) { 33 const parser = comptime clap.Clap(Options) {
39 .defaults = Options { 34 .defaults = Options {
40 .print_values = false, 35 .print_values = false,
41 .a = 0, 36 .a = 0,
@@ -43,22 +38,22 @@ pub fn main() !void {
43 .c = 0, 38 .c = 0,
44 .d = "", 39 .d = "",
45 }, 40 },
46 .params = []Param { 41 .params = []clap.Param {
47 Param.init("a") 42 clap.Param.smart("a")
48 .with("takes_value", Parser.int(i64, 10)), 43 .with("takes_value", clap.Parser.int(i64, 10)),
49 Param.init("b") 44 clap.Param.smart("b")
50 .with("takes_value", Parser.int(u64, 10)), 45 .with("takes_value", clap.Parser.int(u64, 10)),
51 Param.init("c") 46 clap.Param.smart("c")
52 .with("takes_value", Parser.int(u8, 10)), 47 .with("takes_value", clap.Parser.int(u8, 10)),
53 Param.init("d") 48 clap.Param.smart("d")
54 .with("takes_value", Parser.string), 49 .with("takes_value", clap.Parser.string),
55 Param.init("print_values") 50 clap.Param.smart("print_values")
56 .with("short", 'p') 51 .with("short", 'p')
57 .with("long", "print-values"), 52 .with("long", "print-values"),
58 } 53 }
59 }; 54 };
60 55
61 var arg_iter = core.OsArgIterator.init(); 56 var arg_iter = clap.core.OsArgIterator.init();
62 const iter = &arg_iter.iter; 57 const iter = &arg_iter.iter;
63 const command = iter.next(debug.global_allocator); 58 const command = iter.next(debug.global_allocator);
64 59