If the user defines a long option `--foo` and passes `--foo=arg`, the
current behavior is that the option foo is recognized and the argument
is ignored. Change that to be an error.
It is currently not possible to pass arguments to short options using an
equal sign, so this doesn't apply to short options.
Change-Id: I4b0c50398161aebc81789fdb3fce19a80a5f6646
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
opt_arg = next_orig_arg;
*used_next_orig_arg = true;
}
opt_arg = next_orig_arg;
*used_next_orig_arg = true;
}
+ } else if (eq_pos) {
+ /*
+ * Unexpected `--opt=arg` style for a long option which
+ * doesn't accept an argument.
+ */
+ argpar_string_append_printf(&parse_ret->error,
+ "Unexpected argument for option `--%s`",
+ long_opt_name);
+ goto error;
}
/* Create and append option argument */
}
/* Create and append option argument */
"While parsing argument #2 (`--`): Invalid argument",
descrs);
}
"While parsing argument #2 (`--`): Invalid argument",
descrs);
}
+
+ {
+ const struct argpar_opt_descr descrs[] = {
+ { 0, 'c', "chevre", false },
+ ARGPAR_OPT_DESCR_SENTINEL
+ };
+
+ test_fail(
+ "--chevre=fromage",
+ "While parsing argument #1 (`--chevre=fromage`): Unexpected argument for option `--chevre`",
+ descrs);
+ }
succeed_tests();
fail_tests();
return exit_status();
succeed_tests();
fail_tests();
return exit_status();