From 76b434a6be6c05d7d3dae5b77ec8fd886fd715d0 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 15 Nov 2025 18:16:48 -0500 Subject: Bugfix for CLI arg parsing --- src/stdlib/cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/stdlib/cli.c') diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c index 22ed9b94..3c474160 100644 --- a/src/stdlib/cli.c +++ b/src/stdlib/cli.c @@ -397,7 +397,7 @@ bool pop_cli_flag(List_t *args, char short_flag, const char *flag, void *dest, c List_t texts = Text$split(Text$from_str(arg_value), Text(",")); values = EMPTY_LIST; for (int64_t j = 0; j < (int64_t)texts.length; j++) - List$insert_value(&texts, Text$as_c_string(*(Text_t *)(texts.data + j * texts.stride)), I(0), + List$insert_value(&values, Text$as_c_string(*(Text_t *)(texts.data + j * texts.stride)), I(0), sizeof(const char *)); } else { // Case: -fVALUE -- cgit v1.2.3 From 3c80527f5d788ef80abe5cd3a28aabe168a6d69c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 21 Nov 2025 22:19:16 -0500 Subject: Bugfix for optional path CLI args --- src/stdlib/cli.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/stdlib/cli.c') diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c index 3c474160..3523296a 100644 --- a/src/stdlib/cli.c +++ b/src/stdlib/cli.c @@ -220,6 +220,7 @@ static List_t parse_arg_list(List_t args, const char *flag, void *dest, const Ty else if (nonnull == &Int16$info) ((OptionalInt16_t *)dest)->has_value = true; else if (nonnull == &Int8$info) ((OptionalInt8_t *)dest)->has_value = true; else if (nonnull == &Byte$info) ((OptionalByte_t *)dest)->has_value = true; + else if (nonnull == &Path$info) return args; else if (nonnull->tag == StructInfo && nonnull != &Path$info) *(bool *)(dest + nonnull->size) = true; else print_err("Unsupported type: ", generic_as_text(NULL, true, nonnull)); return args; -- cgit v1.2.3 From 0aeacfbd83b0afe8a8ea654bc1554b8d7d29e9b1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 22 Nov 2025 16:56:57 -0500 Subject: CLI arg parsing fixes for optional types --- src/stdlib/cli.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/stdlib/cli.c') diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c index 3523296a..08260171 100644 --- a/src/stdlib/cli.c +++ b/src/stdlib/cli.c @@ -215,12 +215,14 @@ static List_t parse_arg_list(List_t args, const char *flag, void *dest, const Ty return List$from(args, I(2)); } else { args = parse_arg_list(args, flag, dest, nonnull, allow_dashes); - if (nonnull == &Int64$info) ((OptionalInt64_t *)dest)->has_value = true; + if (nonnull == &Int$info || nonnull == &Path$info || nonnull == &Num$info || nonnull == &Num32$info + || nonnull->tag == TextInfo) + return args; + else if (nonnull == &Int64$info) ((OptionalInt64_t *)dest)->has_value = true; else if (nonnull == &Int32$info) ((OptionalInt32_t *)dest)->has_value = true; else if (nonnull == &Int16$info) ((OptionalInt16_t *)dest)->has_value = true; else if (nonnull == &Int8$info) ((OptionalInt8_t *)dest)->has_value = true; else if (nonnull == &Byte$info) ((OptionalByte_t *)dest)->has_value = true; - else if (nonnull == &Path$info) return args; else if (nonnull->tag == StructInfo && nonnull != &Path$info) *(bool *)(dest + nonnull->size) = true; else print_err("Unsupported type: ", generic_as_text(NULL, true, nonnull)); return args; -- cgit v1.2.3 From bb354d6d3626cdc0c2a1b802a954df244cd1facc Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 22 Nov 2025 19:11:55 -0500 Subject: Fixes for conditional expressions for optional types --- src/stdlib/cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/stdlib/cli.c') diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c index 08260171..359220e9 100644 --- a/src/stdlib/cli.c +++ b/src/stdlib/cli.c @@ -216,7 +216,7 @@ static List_t parse_arg_list(List_t args, const char *flag, void *dest, const Ty } else { args = parse_arg_list(args, flag, dest, nonnull, allow_dashes); if (nonnull == &Int$info || nonnull == &Path$info || nonnull == &Num$info || nonnull == &Num32$info - || nonnull->tag == TextInfo) + || nonnull->tag == TextInfo || nonnull->tag == EnumInfo) return args; else if (nonnull == &Int64$info) ((OptionalInt64_t *)dest)->has_value = true; else if (nonnull == &Int32$info) ((OptionalInt32_t *)dest)->has_value = true; -- cgit v1.2.3 From a453ebf215e5e3ec3b27fa5142af77d7e3ca0c92 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 22 Nov 2025 21:49:55 -0500 Subject: Change error message --- src/stdlib/cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/stdlib/cli.c') diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c index 359220e9..04538796 100644 --- a/src/stdlib/cli.c +++ b/src/stdlib/cli.c @@ -202,7 +202,7 @@ static List_t parse_arg_list(List_t args, const char *flag, void *dest, const Ty if ((type->tag == TextInfo || type == &CString$info) && arg[0] == '\\' && arg[1] == '-') { arg = arg + 1; } else if (arg[0] == '-') { - print_err("Not a valid argument for flag ", flag, ": ", arg); + print_err("Not a valid flag: ", arg); } } -- cgit v1.2.3 From 4d8aa867c7f4661167a4742fbdd865ed2449503e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 30 Nov 2025 14:12:01 -0500 Subject: Add `base` parameter to integer parsing functions --- src/stdlib/cli.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/stdlib/cli.c') diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c index 04538796..18da5c5e 100644 --- a/src/stdlib/cli.c +++ b/src/stdlib/cli.c @@ -238,23 +238,23 @@ static List_t parse_arg_list(List_t args, const char *flag, void *dest, const Ty if (parsed.small == 0) print_err("Could not parse argument for ", flag, ": ", arg); *(Int_t *)dest = parsed; } else if (type == &Int64$info) { - OptionalInt64_t parsed = Int64$parse(Text$from_str(arg), NULL); + OptionalInt64_t parsed = Int64$parse(Text$from_str(arg), NONE_INT, NULL); if (!parsed.has_value) print_err("Could not parse argument for ", flag, ": ", arg); *(Int64_t *)dest = parsed.value; } else if (type == &Int32$info) { - OptionalInt32_t parsed = Int32$parse(Text$from_str(arg), NULL); + OptionalInt32_t parsed = Int32$parse(Text$from_str(arg), NONE_INT, NULL); if (!parsed.has_value) print_err("Could not parse argument for ", flag, ": ", arg); *(Int32_t *)dest = parsed.value; } else if (type == &Int16$info) { - OptionalInt16_t parsed = Int16$parse(Text$from_str(arg), NULL); + OptionalInt16_t parsed = Int16$parse(Text$from_str(arg), NONE_INT, NULL); if (!parsed.has_value) print_err("Could not parse argument for ", flag, ": ", arg); *(Int16_t *)dest = parsed.value; } else if (type == &Int8$info) { - OptionalInt8_t parsed = Int8$parse(Text$from_str(arg), NULL); + OptionalInt8_t parsed = Int8$parse(Text$from_str(arg), NONE_INT, NULL); if (!parsed.has_value) print_err("Could not parse argument for ", flag, ": ", arg); *(Int8_t *)dest = parsed.value; } else if (type == &Byte$info) { - OptionalByte_t parsed = Byte$parse(Text$from_str(arg), NULL); + OptionalByte_t parsed = Byte$parse(Text$from_str(arg), NONE_INT, NULL); if (!parsed.has_value) print_err("Could not parse argument for ", flag, ": ", arg); *(Byte_t *)dest = parsed.value; } else if (type == &Bool$info) { -- cgit v1.2.3 From ce26a80bdb61bb8928c49f42bca84c6da4df72c5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 1 Dec 2025 23:43:43 -0500 Subject: Fix CLI arg parsing --- src/stdlib/cli.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/stdlib/cli.c') diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c index 18da5c5e..e30f7ced 100644 --- a/src/stdlib/cli.c +++ b/src/stdlib/cli.c @@ -325,7 +325,8 @@ bool pop_cli_flag(List_t *args, char short_flag, const char *flag, void *dest, c // Case: --flag values... if (i + 1 >= (int64_t)args->length) print_err("No value provided for flag: ", flag); List_t values = List$slice(*args, I(i + 2), I(-1)); - *args = parse_arg_list(values, flag, dest, type, false); + List_t remaining_args = parse_arg_list(values, flag, dest, type, false); + *args = List$concat(List$to(*args, I(i)), remaining_args, sizeof(const char *)); return true; } else if (starts_with(arg + 2, flag) && arg[2 + strlen(flag)] == '=') { // Case: --flag=... @@ -341,7 +342,8 @@ bool pop_cli_flag(List_t *args, char short_flag, const char *flag, void *dest, c } else { values = List(arg_value); } - *args = parse_arg_list(values, flag, dest, type, false); + List_t remaining_args = parse_arg_list(values, flag, dest, type, false); + *args = List$concat(List$to(*args, I(i)), remaining_args, sizeof(const char *)); return true; } } else if (short_flag && arg[0] == '-' && arg[1] != '-' && strchr(arg + 1, short_flag)) { -- cgit v1.2.3