Open tlemo opened 1 month ago
This was fixed here. I'll make a new release soon (long overdue). In the meantime, can you check with the latest commit in the main branch?
Created a new release: https://github.com/p-ranav/argparse/releases/tag/v3.1
@p-ranav I still see this issue with 3.1 version
@p-ranav
Ok to be more specific the issue happens when I set --bar
to accept variable length of arguments:
argparse::ArgumentParser args("arg_test");
args.add_argument("--foo");
args.add_argument("--bar")
.nargs(1, 3)
.choices("a", "b", "c");
So if I give all 3 choices it works ok, but if I give 1 or 2, then it fails:
> ./arg_test --bar a b c --foo x
>
> ./arg_test --bar a b --foo x
Invalid argument "--foo" - allowed options: {a, b, c}
Usage: arg_test [--help] [--version] [--foo VAR] [--bar VAR...]
Optional arguments:
-h, --help shows help message and exits
-v, --version prints version information and exits
--foo
--bar [nargs=1..3]
>
Hi @p-ranav @mikisch81, Regarding variable length list of arguments:
program.add_argument("--input_files")
.nargs(1, 3); // This accepts 1 to 3 arguments.
With the latest version, passing
foo
beforebar
works as expected:But if
foo
is passed afterbar
it's incorrectly rejected: