One can use notifier for parsed options only if they have value_semantic. What is the best way for no-value options to be automatically handled by the given notifier?
Use the zero_tokens
modifier. It seems you also need to use implicit_value
, but anything provided after the option name won't be consumed by the option parser. Instead, when the option is noticed on the command line, the implicit value will be assigned to the option, triggering the option's notifier (so make sure to provide a notifier function). Apparently, it's also important for the option's value type to be string
. I'm not clear on why.
void got_foo(std::string const&);
desc.add_options()
("foo",
po::value()
->implicit_value("")
->zero_tokens()
->notifier(&got_foo),
"foo description")
;