projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lttng: fix argument numbers in add-trigger error messages
[lttng-tools.git]
/
src
/
common
/
argpar-utils
/
argpar-utils.c
diff --git
a/src/common/argpar-utils/argpar-utils.c
b/src/common/argpar-utils/argpar-utils.c
index 1f1f38bccdb69afac143ec88c092089688ff3bac..9ac246f81bd7d659a98bb3e89615c1b2302bbd22 100644
(file)
--- a/
src/common/argpar-utils/argpar-utils.c
+++ b/
src/common/argpar-utils/argpar-utils.c
@@
-23,10
+23,12
@@
* `context_fmt`, if non-NULL, is formatted using `args` and prepended to the
* error message.
*
* `context_fmt`, if non-NULL, is formatted using `args` and prepended to the
* error message.
*
+ * Add `argc_offset` the the argument index mentioned in the error message.
+ *
* The returned string must be freed by the caller.
*/
* The returned string must be freed by the caller.
*/
-static ATTR_FORMAT_PRINTF(
3
, 0)
-char *format_arg_error_v(const struct argpar_error *error,
+static ATTR_FORMAT_PRINTF(
4
, 0)
+char *format_arg_error_v(const struct argpar_error *error,
int argc_offset,
const char **argv, const char *context_fmt, va_list args)
{
char *str = NULL;
const char **argv, const char *context_fmt, va_list args)
{
char *str = NULL;
@@
-54,12
+56,12
@@
char *format_arg_error_v(const struct argpar_error *error,
{
case ARGPAR_ERROR_TYPE_MISSING_OPT_ARG:
{
{
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,
WHILE_PARSING_ARG_N_ARG_FMT "Missing required argument for option `%s`",
const char *arg = argv[orig_index];
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Missing required argument for option `%s`",
- orig_index + 1
, arg
, arg);
+ orig_index + 1
+ argc_offset, argv[orig_index]
, arg);
if (ret < 0) {
goto end;
}
if (ret < 0) {
goto end;
}
@@
-77,11
+79,11
@@
char *format_arg_error_v(const struct argpar_error *error,
if (is_short) {
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Unexpected argument for option `-%c`",
if (is_short) {
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Unexpected argument for option `-%c`",
- orig_index + 1, arg, descr->short_name);
+ orig_index + 1
+ argc_offset
, arg, descr->short_name);
} else {
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Unexpected argument for option `--%s`",
} else {
ret = strutils_appendf(&str,
WHILE_PARSING_ARG_N_ARG_FMT "Unexpected argument for option `--%s`",
- orig_index + 1, arg, descr->long_name);
+ orig_index + 1
+ argc_offset
, arg, descr->long_name);
}
if (ret < 0) {
}
if (ret < 0) {
@@
-92,10
+94,12
@@
char *format_arg_error_v(const struct argpar_error *error,
}
case ARGPAR_ERROR_TYPE_UNKNOWN_OPT:
{
}
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,
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 + argc_offset, argv[orig_index], unknown_opt);
if (ret < 0) {
goto end;
if (ret < 0) {
goto end;
@@
-116,8
+120,9
@@
end:
}
enum parse_next_item_status parse_next_item(struct argpar_iter *iter,
}
enum parse_next_item_status parse_next_item(struct argpar_iter *iter,
- const struct argpar_item **item, const char **argv,
- bool unknown_opt_is_error, const char *context_fmt, ...)
+ const struct argpar_item **item, int argc_offset,
+ const char **argv, bool unknown_opt_is_error,
+ const char *context_fmt, ...)
{
enum argpar_iter_next_status status;
const struct argpar_error *error = NULL;
{
enum argpar_iter_next_status status;
const struct argpar_error *error = NULL;
@@
-143,7
+148,8
@@
enum parse_next_item_status parse_next_item(struct argpar_iter *iter,
}
va_start(args, context_fmt);
}
va_start(args, context_fmt);
- err_str = format_arg_error_v(error, argv, context_fmt, args);
+ err_str = format_arg_error_v(error, argc_offset, argv,
+ context_fmt, args);
va_end(args);
if (err_str) {
va_end(args);
if (err_str) {
This page took
0.024835 seconds
and
4
git commands to generate.