aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-15 17:53:20 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-15 17:53:20 -0400
commit8a1ace4d651a2e1959f194bff02a21b4f704ac07 (patch)
treeee27ef270a61b86666f4aeace774ef3801f4f3a2
parentfa934a9514a4a84a1fff4b2751ff6f0eeed6cae6 (diff)
Fix optional text CLI args
-rw-r--r--compile.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/compile.c b/compile.c
index 61947d51..e910c7a4 100644
--- a/compile.c
+++ b/compile.c
@@ -3530,16 +3530,16 @@ CORD compile_cli_arg_call(env_t *env, CORD fn_name, type_t *fn_type)
}
case TextType: {
code = CORD_all(code, "else if (pop_flag(argv, &i, \"", flag, "\", &flag)) {\n",
- "$", arg->name, " = ", streq(Match(t, TextType)->lang, "Path") ? "Path$cleanup(flag)" : "flag",";\n",
+ "$", arg->name, " = ", streq(Match(non_optional, TextType)->lang, "Path") ? "Path$cleanup(flag)" : "flag",";\n",
"}\n");
break;
}
case ArrayType: {
- if (Match(t, ArrayType)->item_type->tag != TextType)
- compiler_err(NULL, NULL, NULL, "Main function has unsupported argument type: %T (only arrays of Text are supported)", t);
+ if (Match(non_optional, ArrayType)->item_type->tag != TextType)
+ compiler_err(NULL, NULL, NULL, "Main function has unsupported argument type: %T (only arrays of Text are supported)", non_optional);
code = CORD_all(code, "else if (pop_flag(argv, &i, \"", flag, "\", &flag)) {\n",
"$", arg->name, " = Text$split(flag, Pattern(\",\"));\n");
- if (streq(Match(Match(t, ArrayType)->item_type, TextType)->lang, "Path")) {
+ if (streq(Match(Match(non_optional, ArrayType)->item_type, TextType)->lang, "Path")) {
code = CORD_all(code, "for (int64_t j = 0; j < $", arg->name, ".length; j++)\n"
"*(Path_t*)($", arg->name, ".data + j*$", arg->name, ".stride) "
"= Path$cleanup(*(Path_t*)($", arg->name, ".data + j*$", arg->name, ".stride));\n");
@@ -3560,11 +3560,11 @@ CORD compile_cli_arg_call(env_t *env, CORD fn_name, type_t *fn_type)
break;
}
case EnumType: {
- env_t *enum_env = Match(t, EnumType)->env;
+ env_t *enum_env = Match(non_optional, EnumType)->env;
code = CORD_all(code, "else if (pop_flag(argv, &i, \"", flag, "\", &flag)) {\n",
"if (flag.length == 0)\n"
"USAGE_ERR(\"No value provided for '--", flag, "'\");\n");
- for (tag_t *tag = Match(t, EnumType)->tags; tag; tag = tag->next) {
+ for (tag_t *tag = Match(non_optional, EnumType)->tags; tag; tag = tag->next) {
if (tag->type && Match(tag->type, StructType)->fields)
compiler_err(NULL, NULL, NULL,
"The type %T has enum fields with member values, which is not yet supported for command line arguments.");
@@ -3575,7 +3575,7 @@ CORD compile_cli_arg_call(env_t *env, CORD fn_name, type_t *fn_type)
"} else ");
}
code = CORD_all(code, "USAGE_ERR(\"Invalid value provided for '--", flag, "', valid values are: ",
- get_flag_options(t, ", "), "\");\n",
+ get_flag_options(non_optional, ", "), "\");\n",
"}\n");
break;
}