diff options
| author | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2023-09-26 08:45:20 -0700 |
|---|---|---|
| committer | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2023-09-26 08:45:20 -0700 |
| commit | 08954feb5929efa0915163159ff35c930253c9f7 (patch) | |
| tree | 0b0c4b55a500bfd7ee5d7a43f7c481ef39a8ee68 /src/cli/args.zig | |
| parent | 57d81ba9e1f715614e00629042dd710797eba3ef (diff) | |
cli: args can parse unions
Diffstat (limited to 'src/cli/args.zig')
| -rw-r--r-- | src/cli/args.zig | 13 |
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, |
