Skip to content

Commit

Permalink
Add flag to allow continuation of arg parsing after encountering an u…
Browse files Browse the repository at this point in the history
…nknown arg.
  • Loading branch information
handledexception authored and cofyc committed Dec 13, 2021
1 parent a0c76df commit 977def8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion argparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ argparse_parse(struct argparse *self, int argc, const char **argv)
unknown:
fprintf(stderr, "error: unknown option `%s`\n", self->argv[0]);
argparse_usage(self);
exit(EXIT_FAILURE);
if (!self->flags & ARGPARSE_IGNORE_UNKNOWN_ARGS) {
exit(EXIT_FAILURE);
}
}

end:
Expand Down
3 changes: 2 additions & 1 deletion argparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ typedef int argparse_callback (struct argparse *self,
const struct argparse_option *option);

enum argparse_flag {
ARGPARSE_STOP_AT_NON_OPTION = 1,
ARGPARSE_STOP_AT_NON_OPTION = 1 << 0,
ARGPARSE_IGNORE_UNKNOWN_ARGS = 1 << 1,
};

enum argparse_option_type {
Expand Down

0 comments on commit 977def8

Please sign in to comment.