Boost :: program_options: option recognizes the next option as an argument when no argument is provided

I have a program that takes multiple parameters and I want to know when no argument is provided.

This is what happens when I call my program without one arg argument

program -lib

cout: the required argument for option '-lib' is missing

      

This is fine, but when I call my program with additional parameters like

program -lib -out number

      

The variable assigned by lib is set to "-out", although -out was declared as an option. I expect to get the same warning as in the first example.

I can solve this problem by adding a custom notifier to all parameters, the code is below:

void validate_string(const std::string& r)
{
    if (*r.begin() == '-') { 
            throw Something
    }
}

...

("lib", po::value<std::string>(&lib)->notifier(validate_string), "Library")

      

Is there a way to do this with the built-in boost :: program_options mechanism? I don't like my current solution, the parameter declaration looks messy and hard to read. Moreover, he does not receive an assignment.

BTW: I am using allow_long_disguise

, so for long options it is -

allowed

+3


source to share





All Articles