aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-30 17:32:07 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-30 17:32:07 -0500
commiteedfe7ca951c651f6a6cc98b06681c40762cb526 (patch)
tree051ba0fb9ec4a82ed5332408d7ede7fe1e15f75c /stdlib
parent07dd1894b70f537bff13e8f9cb2613e62947c006 (diff)
Support parsing enums as arguments as long as they have no members
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/stdlib.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c
index d56db0e2..5314cebd 100644
--- a/stdlib/stdlib.c
+++ b/stdlib/stdlib.c
@@ -128,6 +128,19 @@ static bool parse_single_arg(const TypeInfo_t *info, char *arg, void *dest)
} else if (info->tag == TextInfo) {
*(OptionalText_t*)dest = Text$from_str(arg);
return true;
+ } else if (info->tag == EnumInfo) {
+ for (int t = 0; t < info->EnumInfo.num_tags; t++) {
+ NamedType_t named = info->EnumInfo.tags[t];
+ if (streq(arg, named.name)) {
+ if (!named.type || (named.type->tag == StructInfo && named.type->StructInfo.num_fields == 0)) {
+ *(int32_t*)dest = (t + 1);
+ return true;
+ } else {
+ errx(1, "Unsupported type for argument parsing: %k.%s", &t, named.name);
+ }
+ }
+ }
+ return false;
} else {
Text_t t = generic_as_text(NULL, false, info);
errx(1, "Unsupported type for argument parsing: %k", &t);