lttng: fix argument numbers in add-trigger error messages
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 25 Aug 2021 18:34:25 +0000 (14:34 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 16 Dec 2021 00:14:46 +0000 (19:14 -0500)
commit35c4b2b3fec47b84bf169557ea23454881b76027
tree0fd2a98a9ac4275694dc4c2d02d6ad692fabe1b0
parentb1a5fb96e7a9385fe421be9d4ab21a75ea11032f
lttng: fix argument numbers in add-trigger error messages

Argument numbers in add-trigger argument parsing error messages are
wrong.  For example:

    $ ./src/bin/lttng/lttng add-trigger --condition event-rule-matches --foo
    Error: While parsing argument #1 (`--foo`): Unknown option `--foo`

This is due to the fact that multiple separate argpar iterators are
created to parse an add-trigger command line.  Iterators are created at
the top-level, to parse the top-level arguments.  Iterators are also
created when parsing a condition or an action, to parse the arguments
specific to that condition or action.  As a result, iterators are passed
a subset of the full command line, and the argument indices in the error
messages are off.

Fix that by passing around an "argc offset", which represents by how
much what's being parsed is offset from the full command-line.  Use that
to adjust the error messages to give indices that make sense to the
user:

    $ ./src/bin/lttng/lttng add-trigger --condition event-rule-matches --foo
    Error: While parsing argument #4 (`--foo`): Unknown option `--foo`

Change-Id: I1d312593d338641d0ec10abe515b640771a1f160
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/add_trigger.cpp
src/bin/lttng/commands/list_triggers.cpp
src/bin/lttng/commands/remove_trigger.cpp
src/common/argpar-utils/argpar-utils.c
src/common/argpar-utils/argpar-utils.h
tests/regression/tools/trigger/test_add_trigger_cli
This page took 0.025518 seconds and 4 git commands to generate.