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

Filtered argc/argv #418

Open
VictorEijkhout opened this issue Jan 30, 2024 · 3 comments
Open

Filtered argc/argv #418

VictorEijkhout opened this issue Jan 30, 2024 · 3 comments

Comments

@VictorEijkhout
Copy link

I'm using two libraries, one cxxopts, that both parse commandline arguments. I would appreciate it if cxxopts (which activates first) could return a filtered argc/argv pair.

Right now I do it by hand: 1. find a marker, 2. truncate argc and use that, and then 3. pass the remainder to the other library.

@jarro2783
Copy link
Owner

What sort of filtering do you want? Do you mean something like stopping at --?

@VictorEijkhout
Copy link
Author

Stopping at -- seems like a reasonable solution.

@jarro2783
Copy link
Owner

Currently it does already stop at --, but then it treats everything else as a positional argument. So you can almost get what you want by having no positional arguments and then fetching the unmatched arguments, which returns a vector of the remaining arguments.
I have previously changed this code to specifically not modify argv at all, because it was causing a lot of people problems to have argv as non const, and they weren't expecting argv to change.
Maybe one small change that would suit your use case is to make the last matched argc accessible. Then you can just pass &argv[new_argc] to your second piece of code.

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