I have a program that takes a few options and I want to recognize when no argument is provided.
This is what happen when I call my program without one option arg
program -lib
cout: the required argument for option '-lib' is missing
That's ok, but when I call my program with additional options, e.g
program -lib -out number
The variable assigned to lib gets the value "-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 the options, code below:
void validate_string(const std::string& r)
{
if (*r.begin() == '-') {
throw Something
}
}
...
("lib", po::value<std::string>(&lib)->notifier(validate_string), "Library")
There's any way of doing this with a build-in mechanism of boost::program_options? I don't like my current solution, the options declaration look messy and is hard to read. Besides -out is not getting assigned.
BTW: I'm using allow_long_disguise
, so single -
is allowed for long options