argpar-utils: tweak unknown option error message
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 24 Aug 2021 01:42:42 +0000 (21:42 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 17 Dec 2021 05:31:09 +0000 (00:31 -0500)
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>
src/common/argpar-utils/argpar-utils.c
tests/regression/tools/trigger/test_add_trigger_cli

index e6572a0b27988a6852de921d20e244fde245d434..6e58ab605aec8da2511053bbc076f9b245b10131 100644 (file)
@@ -92,10 +92,12 @@ char *format_arg_error_v(const struct argpar_error *error,
        }
        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;
index 49cff975a3644803eef1b030cabae9d0a7899cb6..ecf04dd46589a20dbb60225063b42563c82a5c6d 100755 (executable)
@@ -409,7 +409,7 @@ test_success "--action snapshot-session with ctrl/data URIs" "notify-15"\
 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" \
This page took 0.02857 seconds and 5 git commands to generate.