diff options
author | katherine <shmibs@shmibbles.me> | 2018-03-25 00:59:34 -0700 |
---|---|---|
committer | katherine <shmibs@shmibbles.me> | 2018-03-25 00:59:34 -0700 |
commit | fd5b37444a16e85606d56ab27ef0f84ddc20df78 (patch) | |
tree | 515f00e8edd731e7b8e744111ae6056778bfd8b3 /doc | |
parent | 0272f28d559eddc2a3d2ab604f878fefdd9d22a2 (diff) | |
download | simple-opt-fd5b37444a16e85606d56ab27ef0f84ddc20df78.tar.gz |
add error-printing function
Diffstat (limited to 'doc')
-rw-r--r-- | doc/example.c | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/doc/example.c b/doc/example.c index e62e73f..50d8173 100644 --- a/doc/example.c +++ b/doc/example.c @@ -35,38 +35,10 @@ int main(int argc, char **argv) result = simple_opt_parse(argc, argv, options); - /* handle errors */ - switch (result.result_type) { - case SIMPLE_OPT_RESULT_UNRECOGNISED_OPTION: - fprintf(stderr, "err: unrecognised option `%s`\n", - result.option_string); + /* catch any errors and print a default result */ + if (result.result_type != SIMPLE_OPT_RESULT_SUCCESS) { + simple_opt_print_error(stderr, argv[0], options, result); return 1; - - case SIMPLE_OPT_RESULT_BAD_ARG: - fprintf(stderr, "err: bad argument `%s` passed to option `%s`\n", - result.argument_string, result.option_string); - return 1; - - case SIMPLE_OPT_RESULT_MISSING_ARG: - fprintf(stderr, "err: argument expected for option `%s`\n", - result.option_string); - return 1; - - case SIMPLE_OPT_RESULT_OPT_ARG_TOO_LONG: - fprintf(stderr, "internal err: argument passed to option `%s` is too long\n", - result.option_string); - return 1; - - case SIMPLE_OPT_RESULT_TOO_MANY_ARGS: - fprintf(stderr, "internal err: too many cli arguments passed\n"); - return 1; - - case SIMPLE_OPT_RESULT_MALFORMED_OPTION_STRUCT: - fprintf(stderr, "internal err: malformed option struct\n"); - return 1; - - default: - break; } /* if the help flag was passed, print usage */ |