Ravindra Mijar
Ravindra Mijar

Reputation: 1312

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?

Upvotes: 5

Views: 249

Answers (1)

user4815162342
user4815162342

Reputation: 154886

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.

Upvotes: 2

Related Questions