jarro2783 / cxxopts

Lightweight C++ command line option parser
MIT License
4.14k stars 579 forks source link

Filtered argc/argv #418

Open VictorEijkhout opened 7 months ago

VictorEijkhout commented 7 months ago

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 commented 7 months ago

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

VictorEijkhout commented 7 months ago

Stopping at -- seems like a reasonable solution.

jarro2783 commented 6 months ago

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.