cxxopts icon indicating copy to clipboard operation
cxxopts copied to clipboard

Parse argument function changes the argc value

Open cyang-kth opened this issue 4 years ago • 4 comments

The parse function below reset the argc value to one.

https://github.com/jarro2783/cxxopts/blob/b0f67a06de3446aa97a4943ad0ad6086460b2b61/include/cxxopts.hpp#L1333-L1334

That function should not change that value, which is out of expectation.

cyang-kth avatar Mar 04 '20 12:03 cyang-kth

I make it a backup. The function doesn't change argv.

nineKnight avatar Apr 09 '20 07:04 nineKnight

@nineKnight

Thanks. The reason for me to come up with this question is that I want my program to also print out help if there is no option provided.

I try to check if the argc is 0 or not but I found that after the parse function is called. That value gets updated to 0. It means that I need to check the argc before that call. That is unexpected as I think it should not be too difficult to avoid updating that value.

cyang-kth avatar Apr 09 '20 07:04 cyang-kth

Get into the source code, maybe @jarro2783 wanna return the number of args that haven't handled, but the function has already made to returns ParserResult. You can refer to src/example.cpp.

But I think @jarro2783 can make it work better.

nineKnight avatar Apr 09 '20 08:04 nineKnight

I do plan to get to this. See #123.

jarro2783 avatar Apr 19 '20 23:04 jarro2783