cli: args can parse unions

This commit is contained in:
Mitchell Hashimoto
2023-09-26 08:45:20 -07:00
parent 57d81ba9e1
commit 08954feb59

View File

@ -154,10 +154,11 @@ fn parseIntoField(
else => field.type, else => field.type,
}; };
// If we are a struct and have parseCLI, we call that and use // If we are a type that can have decls and have a parseCLI decl,
// that to set the value. // we call that and use that to set the value.
switch (@typeInfo(Field)) { const fieldInfo = @typeInfo(Field);
.Struct => if (@hasDecl(Field, "parseCLI")) { if (fieldInfo == .Struct or fieldInfo == .Union or fieldInfo == .Enum) {
if (@hasDecl(Field, "parseCLI")) {
const fnInfo = @typeInfo(@TypeOf(Field.parseCLI)).Fn; const fnInfo = @typeInfo(@TypeOf(Field.parseCLI)).Fn;
switch (fnInfo.params.len) { switch (fnInfo.params.len) {
// 1 arg = (input) => output // 1 arg = (input) => output
@ -182,8 +183,10 @@ fn parseIntoField(
} }
return; return;
}, }
}
switch (fieldInfo) {
.Enum => { .Enum => {
@field(dst, field.name) = std.meta.stringToEnum( @field(dst, field.name) = std.meta.stringToEnum(
Field, Field,