Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make getopt in C++ do option checking strictly?

I am using getopt to parse inputs for a CLI written in C++. I have long and short options and my struct long_options[] element looks like this:

{"verbose", no_argument, NULL, "v"}

One observation is - on the command line, even if I pass

# mycommand --verb

it still accepts that and routes to the function that handles the verbose behavior. Is there any way to make getopt do a strict option check? It shouldn't accept --verb as --verbose right?

like image 605
Ravindra Mijar Avatar asked Oct 30 '22 16:10

Ravindra Mijar


1 Answers

According to the manual[1] [2] and the source[3] there is no way to turn off matching abbreviated long options.

Your options are to accept this behavior (which has been around for decades and is unlikely to surprise users) or to look for another option parser library that allow turning off long option abbreviations.

like image 65
user4815162342 Avatar answered Nov 09 '22 09:11

user4815162342