Encode error type in argpar_error
With the current API, when encountering an argument parsing error, the
error type (unknown option, missing option argument, unexpected option
argument) is encoded in the returned argpar_iter_next_status value.
In my experience it would be more useful if that information was encoded
in the argpar_error instead.
Imagine a helper function `format_arg_error` that formats an argument
parsing error based on a particular project's needs. That function
needs to take the argpar_iter_next_status along with the argpar_error:
char *format_arg_error(enum argpar_iter_next_status status,
const struct argpar_error *error);
It would be simpler to have the argpar_error object know what type of
error was returned. That makes the argpar_error contain all the
necessary information about the error.
So, the proposed changes are:
- Replace ARGPAR_ITER_NEXT_STATUS_ERROR_* with a single
ARGPAR_ITER_NEXT_STATUS_ERROR, indicating that an argument parsing
error happened.
- Add a new `enum argpar_error_type` type, to represent the 3 argument
parsing error types.
- Add a new `type` property to argpar_error, obtained through
`argpar_error_get_type`.
Note that the argpar_error out parameter of the argpar_iter_next
function is optional. This means that the user can currently receive an
error status (ARGPAR_ITER_NEXT_STATUS_ERROR_{UNKNOWN_OPT,
UNEXPECTED_OPT_ARG,MISSING_OP_ARG}) but not have any more details about
the error. I don't think this is really useful, because the user of the
API wouldn't be able to do make a useful error message by knowing the
type of error but not having the corresponding argpar_error object.
API documentation left to Philippe Proulx.
Change-Id: Ice4db8852030ccd3ba9cbdf3717d9850b8ee7935
This page took 0.025946 seconds and 4 git commands to generate.