-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow many positional arguments #17
Comments
Often cmdline parser updates or returns updated argparse seems to be working on its own storage, in that case a pair of updated auto [first, last] = program.parse_args(argc, argv);
auto tailing = std::vector(first, last); // you got the unused arguments |
I like that idea, very clean. |
Hmm, this is more complicated than I thought. Must extra arguments be consecutive?Given the trailing model, let's say program.add_argument("-I");
program.add_argument("output"); Does this work? ./test pos1 pos2 -I opt1 pos3 If both Extra positional arguments are illegal given existing semanticsIf the above is deemed illegal, whether anything with unused arguments are legal is still debatable. ./test pos1 -I opt1 pos2 pos3 Given the existing parse_args(argc, argv, argparse::throw_if_exceeds_maximum_positional_arguments);
// ^^ this is the default, no need to pass the 3rd argument
auto some_return_value = parse_args(argc, argv, argparse::return_trailing_positional_arguments); Lifetime
Thoughts so far
|
This kind of argument works as if having the "remaining" nargs, inspired by Python's `argparse.REMAINDER`. This change also reduces the size of `Argument` by 8 bytes. See also: https://docs.python.org/2/library/argparse.html#nargs fixes: p-ranav#17
I studied Python's argparse, and was convinced that there are two demands. The first one is to have a kind of The second one is to parse known arguments, and leave the rest to other libraries. The rest of the arguments are not associated with The demand raised in this issue is the former, and I drafted #57 for it. The second demand is worth to investigate separately. |
It would be nice to be able to have a feature whereby you could gather many positional arguments at the end of a command for something like a compiler.
For example, imagine a use case like this:
Currently I don't believe it is possible to do this.
I imagine using it would look something like:
which would just return all positional arguments at the end regardless of how many.
The text was updated successfully, but these errors were encountered: