From 08954feb5929efa0915163159ff35c930253c9f7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 26 Sep 2023 08:45:20 -0700 Subject: [PATCH] cli: args can parse unions --- src/cli/args.zig | 13 ++++++++----- 1 file 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,