Skip to content
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

What is the recommended way to consume the excess of positional args? #34

Open
KOLANICH opened this issue Oct 20, 2021 · 3 comments
Open
Assignees

Comments

@KOLANICH
Copy link
Contributor

Hi again. For implementing "nesting" feature in HydrArgs (in fact, that is probably is one of the most important features in it) I need a way to get the "unconsumed" args. I mean the ones not recognized by the parser of the current level. I wonder what is the recommended way to do it? I guess it can be worked around by adding a dedicated positional argument into the end, but it would spoil help output and also would require a method to remove positional args from the spec (HydrArgs model assummes that args can be appended one-by-one, and in the case something must be done after the last arg is added, the framework has a pair of methods, _seal and _unseal. I can add the code adding a dummy positional arg into _seal, but there is no methods to remove them, so there is nothing that I can put into _unseal that reverts the action done by _seal).

So, if there is no such a feature, it may make sense to introuduce it, for example as a method setting a pointer to std::span<char *> (to place there just a direct subarray of argv).

@saveman saveman self-assigned this Dec 12, 2021
@saveman
Copy link
Owner

saveman commented Dec 19, 2021

Sorry for the late answer.

Not sure if that will suit your needs but originally the concept for nesting was to use subparsers:

https://saveman.github.io/octargs/html/page_argument_types.html
auto subparsers = arg_parser.add_subparsers("command");

@saveman
Copy link
Owner

saveman commented Dec 19, 2021

@KOLANICH If that would not be suitable I have also added some proposal on branch:
https://github.com/saveman/octargs/tree/allow_unconsummed

Please check both solutions and let me know what do you think about them.

@KOLANICH
Copy link
Contributor Author

Thanks, get_unconsummed_args works like a charm. The backend now passes the already existing tests (but the test suite is incomplete (doesn't cover all the functionality I wished to have in HydrArgs) and the functionality implemented in HydArgs is currently incomplete).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants