aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-17 03:29:44 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-17 03:29:44 +0200
commit9a2a61ca289aeee256e104dda807431380eba319 (patch)
treeecd3c0f027eafbc18ab59bba4969b0732eeb8b95
parent917dd2d277476eb7f07d40109f2e160aca36c618 (diff)
downloadffwd-9a2a61ca289aeee256e104dda807431380eba319.tar.gz
ffwd-9a2a61ca289aeee256e104dda807431380eba319.zip
cli: reject unknown --options instead of treating them as text
-rw-r--r--src/cli.c12
-rw-r--r--tests/test_cli.c10
2 files changed, 22 insertions, 0 deletions
diff --git a/src/cli.c b/src/cli.c
index 2729c25..0e3ed7d 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -647,6 +647,18 @@ int main(int argc, char *argv[]) {
else if (!strcmp(f, "-h") || !strcmp(f, "--help")) {
print_usage(prog);
return 0;
+ } else if (!strcmp(f, "--")) {
+ /* End of options: everything after is positional text, even if it
+ * starts with a dash. */
+ arg_start++;
+ break;
+ } else if (f[0] == '-' && f[1] == '-') {
+ /* An unrecognized --option is a hard error, not silently-embedded
+ * text. Catches typos and stale flags (e.g. the removed --backend)
+ * loudly instead of running the default path or embedding the flag. */
+ fprintf(stderr, "unknown option: %s\n", f);
+ print_usage(prog);
+ return 1;
} else
break;
arg_start++;
diff --git a/tests/test_cli.c b/tests/test_cli.c
index 8d56f09..7543717 100644
--- a/tests/test_cli.c
+++ b/tests/test_cli.c
@@ -178,6 +178,16 @@ int main(int argc, char **argv) {
for (size_t i = 0; i < sizeof(bad) / sizeof(bad[0]); i++)
expect(run_cli(bad[i].args, NULL) == 1, bad[i].what);
+ /* Unknown --options fail loudly instead of being silently embedded as text
+ * (guards against typos and removed flags like --backend). A bare -- ends
+ * option parsing so dash-prefixed text can still be embedded. */
+ snprintf(args, sizeof(args), "-d '%s' --backend cuda hi", g_dir);
+ expect(run_cli(args, NULL) == 1, "unknown --option exits 1");
+ expect(file_contains(g_err, "unknown option"), "unknown --option names the flag");
+ snprintf(args, sizeof(args), "-d '%s' -- '-dashy text'", g_dir);
+ expect(run_cli(args, NULL) == 0, "-- terminator allows dash-prefixed text");
+ expect(stdout_is_embedding(dims.hidden), "dash text after -- embeds as one input");
+
if (g_failures) {
fprintf(stderr, "%d CLI check(s) failed\n", g_failures);
return 1;