-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathex-05.custom_config.zig
More file actions
66 lines (61 loc) · 2.25 KB
/
Copy pathex-05.custom_config.zig
File metadata and controls
66 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const std = @import("std");
const zargs = @import("zargs");
const Command = zargs.Command;
const Arg = zargs.Arg;
const TokenIter = zargs.TokenIter;
const String = @import("ztype").String;
const _d = Command.new("D")
.arg(Arg.opt("verbose", u32).short('v').long("verbose"))
.arg(Arg.opt("ignore", bool).short('i').long("ignore"))
.arg(Arg.optArg("output", ?String).long("out").short('o'))
.arg(Arg.posArg("input", ?String));
const _c = Command.new("C")
.arg(Arg.opt("verbose", u32).short('v').long("verbose"))
.arg(Arg.opt("ignore", bool).short('i').long("ignore"))
.arg(Arg.optArg("output", ?String).long("out").short('o'));
const _b = Command.new("B")
.arg(Arg.opt("verbose", u32).short('v').long("verbose"))
.arg(Arg.opt("ignore", bool).short('i').long("ignore"))
.arg(Arg.optArg("output", ?String).long("out").short('o'));
const _a = Command.new("A")
.arg(Arg.opt("verbose", u32).short('v').long("verbose"))
.arg(Arg.opt("ignore", bool).short('i').long("ignore"))
.arg(Arg.optArg("output", ?String).long("out").short('o'));
const a = _a.requireSub("sub").sub(
_b.config(.{ .token = .{
.prefix = .{ .long = "==" },
.terminator = "##",
.connector = ":",
} }).requireSub("sub").sub(
_c.requireSub("sub").sub(_d).config(.{ .token = .{
.prefix = .{ .long = "+++", .short = "@" },
.terminator = "**",
.connector = "=>",
} }),
),
);
const Sub = enum { A, B, C, D };
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
const allocator = gpa.allocator();
pub fn main() !void {
const cmd = Command.new("config")
.arg(Arg.posArg("sub", Sub)
.callbackFn(struct {
fn f(v: *Sub) void {
const line = switch (v.*) {
.A => "-h",
.B => "B -h",
.C => "B C @h",
.D => "B C D @h",
};
var it = TokenIter.initLine(line, null, .{}) catch unreachable;
it.debug(true);
var args = a.parseFrom(&it, allocator) catch unreachable;
defer a.destroy(&args, allocator);
}
}.f));
var it = try TokenIter.init(allocator, .{});
defer it.deinit();
_ = try it.next();
_ = try cmd.parseFrom(&it, null);
}