Add parsing error API
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 2 Jun 2021 15:40:32 +0000 (11:40 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 4 Jun 2021 17:59:12 +0000 (13:59 -0400)
This patch adds the `struct argpar_error` type which contains details
about a parsing error. Get said details with the new dedicated property
getters:

argpar_error_orig_index():
    Returns the index of the original argument for which the error
    occurred.

argpar_error_unknown_opt_name():
    Returns the name of the unknown option for which the error occurred.

argpar_error_opt_descr():
    Returns the descriptor of the option for which the error occurred.

    Also sets an output boolean parameter to whether said option is
    short or long.

Destroy a parsing error with argpar_error_destroy().

argpar_iter_next() now sets such a parsing error object on parsing error
instead of an error string. You can build a corresponding error string
from the properties of the parsing error object.

See the updated user documentation in `argpar.h` for more details.

In `test_argpar.c`, test_fail() now ensures that argpar_iter_next() sets
an parsing error object and that, depending on the returned status code,
its properties have expected values. I moved the "unknown option" tests
from succeed_tests() to fail_tests() as this was a vestige of the
`fail_on_unknown_opt` parameter of argpar_parse().

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I7b988253f653f96e6bf6859ae1b48bbcf6fb406d


No differences found
This page took 0.02291 seconds and 4 git commands to generate.