summaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2023-09-26 08:45:20 -0700
committerMitchell Hashimoto <mitchell.hashimoto@gmail.com>2023-09-26 08:45:20 -0700
commit08954feb5929efa0915163159ff35c930253c9f7 (patch)
tree0b0c4b55a500bfd7ee5d7a43f7c481ef39a8ee68 /src/cli
parent57d81ba9e1f715614e00629042dd710797eba3ef (diff)
cli: args can parse unions
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/args.zig13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/cli/args.zig b/src/cli/args.zig
index 833914c88..9eb09b3cc 100644
--- a/src/cli/args.zig
+++ b/src/cli/args.zig
@@ -154,10 +154,11 @@ fn parseIntoField(
else => field.type,
};
- // If we are a struct and have parseCLI, we call that and use
- // that to set the value.
- switch (@typeInfo(Field)) {
- .Struct => if (@hasDecl(Field, "parseCLI")) {
+ // If we are a type that can have decls and have a parseCLI decl,
+ // we call that and use that to set the value.
+ const fieldInfo = @typeInfo(Field);
+ if (fieldInfo == .Struct or fieldInfo == .Union or fieldInfo == .Enum) {
+ if (@hasDecl(Field, "parseCLI")) {
const fnInfo = @typeInfo(@TypeOf(Field.parseCLI)).Fn;
switch (fnInfo.params.len) {
// 1 arg = (input) => output
@@ -182,8 +183,10 @@ fn parseIntoField(
}
return;
- },
+ }
+ }
+ switch (fieldInfo) {
.Enum => {
@field(dst, field.name) = std.meta.stringToEnum(
Field,