From: Simon Marchi Date: Tue, 24 Aug 2021 01:42:42 +0000 (-0400) Subject: argpar-utils: tweak unknown option error message X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b1a5fb96e7a9385fe421be9d4ab21a75ea11032f;p=lttng-tools.git argpar-utils: tweak unknown option error message 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 Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/argpar-utils/argpar-utils.c b/src/common/argpar-utils/argpar-utils.c index 1f1f38bcc..6f5548917 100644 --- a/src/common/argpar-utils/argpar-utils.c +++ b/src/common/argpar-utils/argpar-utils.c @@ -54,7 +54,7 @@ char *format_arg_error_v(const struct argpar_error *error, { case ARGPAR_ERROR_TYPE_MISSING_OPT_ARG: { - int orig_index = argpar_error_orig_index(error); + const int orig_index = argpar_error_orig_index(error); const char *arg = argv[orig_index]; ret = strutils_appendf(&str, @@ -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; diff --git a/tests/regression/tools/trigger/test_add_trigger_cli b/tests/regression/tools/trigger/test_add_trigger_cli index 49cff975a..ecf04dd46 100755 --- a/tests/regression/tools/trigger/test_add_trigger_cli +++ b/tests/regression/tools/trigger/test_add_trigger_cli @@ -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" \