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
c ++ boost boost-program-options


source to share


No one has answered this question yet

See similar questions:

sixteen
How do I use boost :: program_options to accept an optional flag?

or similar:

sixteen
Using '-' as an option end marker with boost :: program_options
nine
C ++ boost :: program_options reading arguments compatible with getopt_long
6
Compiling boost :: program_options on Mac OS X with g ++ 4.8 (Mac ports)
2
speed up process_process case insensitively
1
How to avoid errors from non-existent arguments in boost :: program_options?
1
boost :: program_options adds vector options with similar names
0
defaults and implicit arguments in formatting options
0
Linker error with Boost & C ++ on OSX
0
How to pass program parameters to boost without an argument name, having all the other options available in full
0
boost failed to compile with apple llvm program_options



All Articles
Loading...
X
Show
Funny
Dev
Pics