-
Notifications
You must be signed in to change notification settings - Fork 6
/
covademo.zig
676 lines (656 loc) · 25.2 KB
/
covademo.zig
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
//! Example usage of Cova.
//! Comptime Setup, Runtime Use.
const std = @import("std");
const builtin = @import("builtin");
const fmt = std.fmt;
const io = std.io;
const log = std.log;
const mem = std.mem;
const meta = std.meta;
const proc = std.process;
const ComptimeStringMap = std.ComptimeStringMap;
const StringHashMap = std.StringHashMap;
const testing = std.testing;
const cova = @import("cova");
const Command = cova.Command;
const Option = cova.Option;
const Value = cova.Value;
const ex_structs = @import("example_structs.zig");
const conf_optimized = Command.Config.optimized(.{});
pub const CommandT = Command.Custom(.{
.global_help_prefix = "CovaDemo",
.global_vals_mandatory = false,
.help_category_order = &.{ .Prefix, .Header, .Aliases, .Values, .Options, .Commands },
.allow_abbreviated_cmds = true,
//.allow_arg_indices = false,
.global_usage_fn = struct{
fn usage(self: anytype, writer: anytype, _: ?mem.Allocator) !void {
const CmdT = @TypeOf(self.*);
const OptT = CmdT.OptionT;
const indent_fmt = CmdT.indent_fmt;
var no_args = true;
var pre_sep: []const u8 = "";
try writer.print("USAGE\n", .{});
if (self.opts) |opts| {
no_args = false;
try writer.print("{s}{s} [", .{
indent_fmt,
self.name,
});
for (opts) |opt| {
try writer.print("{s} {s}{s} ", .{
pre_sep,
OptT.long_prefix orelse opt.short_prefix,
opt.long_name orelse &.{ opt.short_name orelse 0 },
});
pre_sep = "| ";
}
try writer.print("]\n", .{});
}
if (self.sub_cmds) |cmds| {
no_args = false;
try writer.print("{s}{s} [", .{
indent_fmt,
self.name,
});
pre_sep = "";
for (cmds) |cmd| {
try writer.print("{s} {s} ", .{
pre_sep,
cmd.name,
});
pre_sep = "| ";
}
try writer.print("]\n", .{});
}
if (no_args) try writer.print("{s}{s}{s}", .{
indent_fmt,
indent_fmt,
self.name,
});
}
}.usage,
//.help_header_fmt =
// \\HELP
// \\{s}COMMAND: {s}
// \\
// \\{s}DESCRIPTION: {s}
// \\
// \\
//,
//.global_help_fn = struct{
// fn help(self: anytype, writer: anytype, _: mem.Allocator) !void {
// const CmdT = @TypeOf(self.*);
// const OptT = CmdT.OptionT;
// const indent_fmt = CmdT.indent_fmt;
//
// try writer.print("{s}\n", .{ self.help_prefix });
// try self.usage(writer);
// try writer.print("\n", .{});
// try writer.print(CmdT.help_header_fmt, .{
// indent_fmt, self.name,
// indent_fmt, self.description
// });
// if (self.sub_cmds) |cmds| {
// try writer.print("SUBCOMMANDS\n", .{});
// for (cmds) |cmd| {
// try writer.print("{s}{s}: {s}\n", .{
// indent_fmt,
// cmd.name,
// cmd.description,
// });
// }
// try writer.print("\n", .{});
// }
// if (self.opts) |opts| {
// try writer.print("OPTIONS\n", .{});
// for (opts) |opt| {
// try writer.print(
// \\{s}{s}{s} "{s} ({s})"
// \\{s}{s}{s}
// \\
// \\
// , .{
// indent_fmt,
// OptT.long_prefix orelse OptT.short_prefix, opt.long_name orelse "",
// opt.val.name(), opt.val.childType(),
// indent_fmt, indent_fmt,
// opt.description,
// }
// );
// }
// }
// if (self.vals) |vals| {
// try writer.print("VALUES\n", .{});
// for (vals) |val| {
// try writer.print("{s}", .{ indent_fmt });
// try val.usage(writer);
// try writer.print("\n", .{});
// }
// try writer.print("\n", .{});
// }
// }
//}.help,
//.global_case_sensitive = false,
.opt_config = .{
//.usage_fmt = "{u}{?u}{s} {s}{?s} <{s} ({s})>",
//.allow_arg_indices = false,
//.global_case_sensitive = false,
//.usage_fn = struct{
// fn usage(self: anytype, writer: anytype, _: ?mem.Allocator) !void {
// const short_prefix = @TypeOf(self.*).short_prefix;
// const long_prefix = @TypeOf(self.*).long_prefix;
// try writer.print("{?u}{?u}, {?s}{?s}", .{
// short_prefix,
// self.short_name,
// long_prefix,
// self.long_name,
// }
// );
// }
//}.usage,
.global_help_fn = struct{
fn help(self: anytype, writer: anytype, _: ?mem.Allocator) !void {
const indent_fmt = @TypeOf(self.*).indent_fmt;
try self.usage(writer);
try writer.print("\n{?s}{?s}{?s}{s}", .{ indent_fmt, indent_fmt, indent_fmt, self.description });
}
}.help
},
.val_config = .{
//.allow_arg_indices = false,
//.custom_types = &.{ DemoStruct.InnerEnum },
//.custom_types = &.{ SimpleEnum },
.child_type_parse_fns = &.{
//.{
// .ChildT = bool,
// .parse_fn = Value.ParsingFns.Builder.altBool(
// &.{ "true", "t", "yes", "y", "1", "ok" },
// &.{ "false", "f", "no", "n", "0" },
// .Error
// )
//},
//.{
// .ChildT = u1024,
// .parse_fn = struct{ fn testFn(arg: []const u8, alloc: mem.Allocator) !u1024 { _ = arg; _ = alloc; return 69696969696969; } }.testFn,
//},
},
.child_type_aliases = &.{
.{
.ChildT = []const u8,
.alias = "text",
},
.{
.ChildT = bool,
.alias = "toggle",
},
.{
.ChildT = [6]u8,
.alias = "byte_array",
},
},
},
//.global_usage_fn = struct{
// fn usage(_: anytype, writer: anytype, _: ?mem.Allocator) !void {
// // In a real implementation checks should be done to ensure `self` is a suitable Command Type and extract its sub Argument Types.
// try writer.print("This is an overriding usage message!\n\n", .{});
// }
//}.usage,
});
pub const ValueT = CommandT.ValueT;
//pub const log_level: log.Level = .err;
pub const SimpleEnum = enum{
a,
b,
};
pub const DemoStruct = struct{
pub const InnerStruct = struct{
in_bool: bool = false,
in_float: f32 = 0,
h_string: []const u8 = "Just a test for fields starting with 'h'",
};
pub const InnerEnum = enum(u2){
red,
blue,
green,
};
// Command
inner_cmd: InnerStruct = .{
.in_bool = true,
.in_float = 0,
},
// Options
int: ?i32 = 26,
str: ?[]const u8 = "Demo Opt string.",
str2: ?[]const u8 = "Demo Opt string 2.",
flt: ?f16 = 0,
int2: ?u16 = 0,
multi_int: [3]?u8,
multi_str: [5]?[]const u8,
rgb_enum: ?InnerEnum = .blue,
// Values
struct_bool: bool = true,
struct_str: []const u8 = "Demo Struct string.",
struct_int: i64 = 8967,
multi_int_val: [2]u16,
_ignored_int: i8 = 15,
// Cova Argument Types
//cova_val_int: ValueT = ValueT.ofType(i8, .{
// .name = "cova_val_int",
// .description = "A test cova Value within a struct.",
// .default_val = 50,
//}),
};
pub const DemoUnion = union(enum) {
// Options
int: ?i32,
str: ?[]const u8,
// Values
union_uint: u8,
union_str: []const u8,
};
pub fn demoFn(int: i32, string: []const u8, array: [6]u8) void {
log.info("Demo function result:\n - Int: {d}\n - String: {s}\n - Array: {s}", .{ int, string, array[0..] });
}
// Comptime Setup Command
pub const setup_cmd: CommandT = .{
.name = "covademo",
.description = "A demo of the Cova command line argument parser.",
.examples = &.{
"covademo -b --string \"Optional String\"",
"covademo -i 0 -i=1 -i2 -i=3,4,5 -i6,7 --int 8 --int=9",
"covademo --file \"/some/file\"",
},
.cmd_groups = &.{ "RAW", "STRUCT-BASED", "FN-BASED" },
.opt_groups = &.{ "INT", "BOOL", "STRING" },
.val_groups = &.{ "INT", "BOOL", "STRING" },
.sub_cmds_mandatory = false,
//.mandatory_opt_groups = &.{ "BOOL" },
.sub_cmds = &.{
.{
.name = "sub-cmd",
.alias_names = &.{ "alias-cmd", "test-alias" },
.description = "A demo sub command.",
.examples = &.{
"covademo sub-cmd 3.14",
},
.cmd_group = "RAW",
.opts = &.{
.{
.name = "nested_int_opt",
.short_name = 'i',
//.long_name = "nested_int",
.val = ValueT.ofType(u8, .{
.name = "nested_int_val",
.description = "A nested integer value.",
.default_val = 203,
}),
.description = "A nested integer option.",
},
.{
.name = "nested_str_opt",
.short_name = 's',
.long_name = "nested_str",
.val = ValueT.ofType([]const u8, .{
.name = "nested_str_val",
.description = "A nested string value.",
.default_val = "A nested string value.",
}),
.description = "A nested string option.",
},
},
.vals = &.{
ValueT.ofType(f32, .{
.name = "nested_float_val",
.description = "A nested float value.",
.default_val = 0,
}),
}
},
.{
.name = "basic",
.alias_names = &.{ "basic-cmd" },
.description = "The most basic Command.",
.cmd_group = "RAW",
},
.{
.name = "nest-1",
.description = "Nested Level 1.",
.sub_cmds = &.{
.{
.name = "nest-2",
.description = "Nested Level 2.",
.sub_cmds = &.{
.{
.name = "nest-3",
.description = "Nested Level 3.",
.sub_cmds = &.{
.{
.name = "nest-4",
.description = "Nested Level 4.",
}
},
.opts = &.{
.{
.name = "inheritable",
.description = "Inheritable Option",
.inheritable = true,
.short_name = 'i',
.long_name = "inheritable",
}
}
}
}
}
}
},
CommandT.from(DemoStruct, .{
.cmd_name = "struct-cmd",
.cmd_description = "A demo sub command made from a struct.",
.attempt_short_opts = true,
//.cmd_hidden = true,
.cmd_group = "STRUCT-BASED",
.sub_cmds_mandatory = false,
.default_val_opts = true,
.sub_descriptions = &.{
.{ "inner_cmd", "An inner/nested command for struct-cmd" },
.{ "int", "The first Integer Value for the struct-cmd." },
},
}),
CommandT.from(DemoUnion, .{
.cmd_name = "union-cmd",
.cmd_description = "A demo sub command made from a union.",
.cmd_group = "STRUCT-BASED",
.sub_descriptions = &.{
.{ "int", "The first Integer Value for the union-cmd." },
.{ "str", "The first String Value for the union-cmd." },
},
}),
CommandT.from(@TypeOf(demoFn), .{
.cmd_name = "fn-cmd",
.cmd_description = "A demo sub command made from a function.",
.cmd_group = "FN-BASED",
.sub_descriptions = &.{
.{ "int", "The first Integer Value for the fn-cmd." },
.{ "string", "The first String Value for the fn-cmd." },
.{ "byte_array", "A 6-Byte Array for fn-cmd" },
},
.ignore_incompatible = false,
}),
CommandT.from(ex_structs.add_user, .{
.cmd_name = "add-user",
.cmd_group = "STRUCT-BASED",
.cmd_description = "A demo sub command for adding a user.",
}),
},
.opts = &.{
.{
.name = "string_opt",
.description = "A string option. (Can be given up to 4 times.)",
//.hidden = true,
.inheritable = true,
.opt_group = "STRING",
.short_name = 's',
.long_name = "string",
.alias_long_names = &.{ "text" },
.allow_empty = true,
.val = ValueT.ofType([]const u8, .{
.name = "string_val",
.description = "A string value.",
.default_val = "Default string value.",
.alias_child_type = "string",
.set_behavior = .Multi,
.max_entries = 4,
.parse_fn = Value.ParsingFns.toUpper,
}),
},
.{
.name = "int_opt",
.description = "An integer option. (Can be given up to 10 times.)",
.opt_group = "INT",
.short_name = 'i',
.long_name = "int",
.val = ValueT.ofType(i16, .{
.name = "int_val",
.description = "An integer value.",
.valid_fn = struct{ fn valFn(int: i16, alloc: mem.Allocator) bool { _ = alloc; return int < 666; } }.valFn,
.set_behavior = .Multi,
.max_entries = 10,
}),
},
//.{
// .name = "uint_opt",
// .description = "An unsigned integer option. (Can be given up to 10 times.)",
// .opt_group = "INT",
// .short_name = 'U',
// .long_name = "uint",
// .val = ValueT.ofType(u1024, .{
// .name = "uint_val",
// .description = "An unsigned integer value.",
// .set_behavior = .Multi,
// .max_entries = 10,
// }),
//},
.{
.name = "float_opt",
.description = "An float option. (Can be given up to 10 times.)",
//.opt_group = "INT",
.short_name = 'f',
.long_name = "float",
.val = ValueT.ofType(f16, .{
.name = "float_val",
.description = "A float value.",
.valid_fn = Value.ValidationFns.Builder.inRange(f16, 0.0, 36_000.0, true),
.set_behavior = .Multi,
.max_entries = 10,
}),
},
.{
.name = "file_opt",
.description = "A filepath option.",
.opt_group = "STRING",
.short_name = 'F',
.long_name = "file",
.val = ValueT.ofType([]const u8, .{
.name = "filepath",
.description = "A filepath value.",
.alias_child_type = "filepath",
.valid_fn = Value.ValidationFns.validFilepath,
}),
},
.{
.name = "ordinal_opt",
.description = "An ordinal number option.",
.opt_group = "STRING",
.short_name = 'o',
.long_name = "ordinal",
.val = ValueT.ofType([]const u8, .{
.name = "ordinal_val",
.description = "An ordinal number value.",
.valid_fn = Value.ValidationFns.ordinalNum,
}),
},
.{
.name = "cardinal_opt",
.description = "A cardinal number option.",
.opt_group = "INT",
.short_name = 'c',
.long_name = "cardinal",
.val = ValueT.ofType(u8, .{
.name = "cardinal_val",
.description = "A cardinal number value.",
.parse_fn = Value.ParsingFns.Builder.asEnumType(enum(u8) { zero, one, two }),
.set_behavior = .Multi,
.max_entries = 3,
}),
},
.{
.name = "toggle_opt",
.description = "A toggle/boolean option.",
.opt_group = "BOOL",
.short_name = 't',
.long_name = "toggle",
.alias_long_names = &.{ "switch" },
.val = ValueT.ofType(bool, .{
.name = "toggle_val",
.description = "A toggle/boolean value.",
}),
},
.{
.name = "bool_opt",
.description = "A toggle/boolean option.",
.opt_group = "BOOL",
.short_name = 'b',
.long_name = "bool",
//.mandatory = true,
.val = ValueT.ofType(bool, .{
.name = "bool_val",
.description = "A toggle/boolean value.",
//.parse_fn = Value.ParsingFns.Builder.altBool(&.{ "true", "t", "yes", "y", "1" }, &.{}, .False),
}),
},
.{
.name = "verbosity_opt",
.description = "Set the CovaDemo verbosity level. (WIP)",
.inheritable = true,
.short_name = 'v',
.long_name = "verbosity",
.val = ValueT.ofType(u4, .{
.name = "verbosity_level",
.description = "The verbosity level from 0 (err) to 3 (debug).",
.default_val = 3,
.valid_fn = struct{ fn valFn(val: u4, _: mem.Allocator) bool { return val >= 0 and val <= 3; } }.valFn,
}),
},
},
.vals = &.{
ValueT.ofType([]const u8, .{
.name = "cmd_str",
.val_group = "STRING",
.description = "A string value for the command.",
.parse_fn = Value.ParsingFns.trimWhitespace,
}),
ValueT.ofType(bool, .{
.name = "cmd_bool",
.description = "A boolean value for the command.",
.set_behavior = .Multi,
.max_entries = 10,
.parse_fn = Value.ParsingFns.Builder.altBool(&.{ "true", "t", "yes", "y", "1" }, &.{ "false", "f", "no", "n", "0" }, .Error),
}),
ValueT.ofType(u64, .{
.name = "cmd_u64",
.description = "A u64 value for the command.",
.default_val = 654321,
.set_behavior = .Multi,
.max_entries = 3,
.parse_fn = struct{ fn parseFn(arg: []const u8, alloc: mem.Allocator) !u64 { _ = alloc; return (try fmt.parseInt(u64, arg, 0)) * 100; } }.parseFn,
.valid_fn = Value.ValidationFns.Builder.inRange(u64, 123456, 9999999999, true),
}),
}
};
pub fn main() !void {
// Setup
//var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
//var alloc_buf: [100 << 10]u8 = undefined;
//var fba = std.heap.FixedBufferAllocator.init(alloc_buf[0..]);
//var arena = std.heap.ArenaAllocator.init(fba.allocator());
//defer arena.deinit();
//const alloc = arena.allocator();
var gpa = std.heap.GeneralPurposeAllocator(.{ .verbose_log = builtin.mode == .Debug }){};
const alloc = gpa.allocator();
defer {
if (gpa.deinit() != .ok) {
if (builtin.mode == .Debug and gpa.detectLeaks()) log.err("Memory leak detected!", .{});
}
else log.debug("Memory freed. No leaks detected.", .{});
}
const stdout_raw = io.getStdOut().writer();
var stdout_bw = io.bufferedWriter(stdout_raw);
const stdout = stdout_bw.writer();
var main_cmd = try setup_cmd.init(alloc, .{});
defer main_cmd.deinit();
var args_iter = try cova.ArgIteratorGeneric.init(alloc);
defer args_iter.deinit();
// Parsing
cova.parseArgs(&args_iter, CommandT, main_cmd, stdout, .{
//.auto_handle_usage_help = false,
}) catch |err| switch (err) {
error.UsageHelpCalled => {},
else => return err,
};
try stdout_bw.flush();
// Analysis
// - Debug Output of Commands after Parsing.
try stdout.print("\nCova Demo Argument Results:\n", .{});
try cova.utils.displayCmdInfo(CommandT, main_cmd, alloc, stdout, true);
try stdout_bw.flush();
// - Individual Command Analysis (this is how analysis would look in a normal program)
log.debug("Main Cmd", .{});
// -- Get Values
const val_map = try main_cmd.getVals(.{ .arg_group = "STRING" });
var val_iter = val_map.valueIterator();
log.debug("Get String Values:", .{});
while (val_iter.next()) |str_val| log.debug("- {s}", .{ str_val.getAs([]const u8) catch "[value not set]" });
// -- Check Options
const opts_check_names: []const []const u8 = &.{ "int_opt", "string_opt", "float_opt", "bool_opt" };
const and_opts_check = main_cmd.checkOpts(opts_check_names, .{ .logic = .AND });
const or_opts_check = main_cmd.checkOpts(opts_check_names, .{ .logic = .OR });
const xor_opts_check = main_cmd.checkOpts(opts_check_names, .{ .logic = .XOR });
log.debug(
\\ Check Options: {s}
\\ - AND: {}
\\ - OR: {}
\\ - XOR: {}
\\
, .{
opts_check_names,
and_opts_check,
or_opts_check,
xor_opts_check,
}
);
var main_opts = try main_cmd.getOpts(.{});
if (main_opts.get("string_opt")) |str_opt| strOpt: {
if (str_opt.val.isEmpty() and str_opt.val.isSet()) {
log.debug("This Option was set, but intentionally left empty.", .{});
break :strOpt;
}
const opt_strs = try str_opt.val.getAllAs([]const u8);
log.debug("Option Strings (--string): {d}", .{ opt_strs.len });
for (opt_strs, 0..) |str, idx| log.debug(" {d}. {s}", .{ idx, str });
}
//if (main_cmd.opts) |main_opts| {
// for (main_opts) |opt| log.debug("-> Opt: {s}, Idx: {d}", .{ opt.name, opt.arg_idx orelse continue });
//}
if (main_cmd.checkSubCmd("sub-cmd"))
log.debug("-> Sub Cmd", .{});
if (main_cmd.matchSubCmd("add-user")) |add_user_cmd|
log.debug("-> Add User Cmd\nTo Struct:\n{any}\n\n", .{ try add_user_cmd.to(ex_structs.add_user, .{}) });
if (main_cmd.matchSubCmd("struct-cmd")) |struct_cmd| structCmd: {
log.debug("Parent Cmd (struct-cmd): {s]}", .{ struct_cmd.parent_cmd.?.name });
log.debug("Parent Cmd (int-opt / int-val): {s} / {s}", optPar: {
const struct_cmd_opts = struct_cmd.getOpts(.{}) catch break: optPar .{ "[no opts]", "" };
const int_opt = struct_cmd_opts.get("int") orelse break: optPar .{ "[no int opt]", "" };
break :optPar .{ if (int_opt.parent_cmd) |p_cmd| p_cmd.name else "[no parent?]", if (int_opt.val.parent_cmd) |p_cmd| p_cmd.name else "[no parent?]" };
});
const demo_struct = try struct_cmd.to(DemoStruct, .{ .default_val_opts = true });
log.debug("-> Struct Cmd\n{any}", .{ demo_struct });
if (struct_cmd.matchSubCmd("inner-cmd")) |inner_cmd|
log.debug("->-> Inner Cmd\n{any}", .{ try inner_cmd.to(DemoStruct.InnerStruct, .{}) });
//for (struct_cmd.opts orelse break :structCmd) |opt| log.debug("->-> Opt: {s}, Idx: {d}", .{ opt.name, opt.arg_idx orelse continue });
break :structCmd;
}
if (main_cmd.checkSubCmd("union-cmd"))
log.debug("-> Union Cmd\nTo Union:\n{any}\n\n", .{ meta.activeTag(try main_cmd.sub_cmd.?.to(DemoUnion, .{})) });
if (main_cmd.matchSubCmd("fn-cmd")) |fn_cmd| {
log.debug("-> Fn Cmd", .{});
try fn_cmd.callAs(demoFn, null, void);
}
// Tokenization Example
const arg_str = "cova struct-cmd --multi-str \"demo str\" -m 'a \"quoted string\"' -m \"A string using an 'apostrophe'\" -m (quick parans test) 50";
const args = try cova.tokenizeArgs(arg_str, alloc, .{ .groupers_open = "\"'(", .groupers_close = "\"')" });
defer alloc.free(args);
log.debug("Tokenized Args:\n{s}", .{ args });
// Optimized Config
//log.debug("Optimized Config:\n{any}", .{ conf_optimized });
}