Add the "While parsing argument #X" context, that is used when other
errors are encountered. Before:
Error: Unknown option `--hello`
After:
Error: While parsing argument #1 (`--hello`): Unknown option `--hello`
Change-Id: Ifd84a1e8b1fe0456e09ff154cc515eaa2850a7e1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
}
case ARGPAR_ERROR_TYPE_UNKNOWN_OPT:
{
+ int orig_index = argpar_error_orig_index(error);
const char *unknown_opt = argpar_error_unknown_opt_name(error);
ret = strutils_appendf(&str,
- "Unknown option `%s`", unknown_opt);
+ WHILE_PARSING_ARG_N_ARG_FMT "Unknown option `%s`",
+ orig_index + 1, argv[orig_index], unknown_opt);
if (ret < 0) {
goto end;
test_failure "no args" "Error: Missing --condition."
test_failure "unknown option" \
- "Error: Unknown option \`--hello\`" \
+ "Error: While parsing argument #1 (\`--hello\`): Unknown option \`--hello\`" \
--hello
test_failure "missing --action" \