From 1c261563a219695133948df29cf3a5d673df7911 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 13 Mar 2021 12:26:12 +0100 Subject: [PATCH] Make it possible to treat non options as unknown arguments --- argparse.c | 3 +++ argparse.h | 1 + 2 files changed, 4 insertions(+) diff --git a/argparse.c b/argparse.c index 3521f534c..5568cd30a 100644 --- a/argparse.c +++ b/argparse.c @@ -233,6 +233,9 @@ argparse_parse(struct argparse *self, int argc, const char **argv) if (self->flags & ARGPARSE_STOP_AT_NON_OPTION) { goto end; } + if (self->flags & ARGPARSE_NON_OPTION_IS_INVALID) { + goto unknown; + } // if it's not option or is a single char '-', copy verbatim self->out[self->cpidx++] = self->argv[0]; continue; diff --git a/argparse.h b/argparse.h index 44ce835a0..1efc06052 100644 --- a/argparse.h +++ b/argparse.h @@ -23,6 +23,7 @@ typedef int argparse_callback (struct argparse *self, enum argparse_flag { ARGPARSE_STOP_AT_NON_OPTION = 1, + ARGPARSE_NON_OPTION_IS_INVALID = 2, }; enum argparse_option_type {