Open rouault opened 8 months ago
Interestingly there is a similar situation to that issue at https://github.com/p-ranav/argparse/blob/cebee4bb4b6c4ec78232a39e6c94b3a32e148ac1/test/test_optional_arguments.cpp#L167 . But this requires specifying the optional argument after the positional one(s). Which doesn't match the advertize usage: Usage: test [--help] [--version] [-s VAR...] [input]...
Hi @rouault,
./mytest --a 1 2 foo
in this example, foo
will be consumed by --b
option.@rouault @p-ranav, If documenting is ok, I can create a PR.
Consider the following parser
The following invocations work:
but not
The issue is that Argument::consume() consumes the
foo
value when parsing--a
.I believe that in the general case, such parser will be ambiguous. It can be de-ambiguated at least (only?) in the following particular situation: when the positional arguments have a fixed number of values each.
I was also thinking about criteria based on the typing of the arguments. For example if we know that the type of a --a value is a number whereas the type of the positional argument is a non-number strings, but that gets really complicated.
So what are our potential options to resolve the issue: