The boost option parser allows one to assign a variable to store the option value, instead of using the so_long["typing"].as<bool>()
way:
bool flag_value;
entries.add_options()
("flag", value<bool>(&flag_value), "a simple flag value");
......
cout<<"flag value is: "<<flag_value<<endl;
However, the above option declaration does not create a simple flag option. It actually requires you to enter something as the value (--flag true|false|on|off|yes|no|1|0), which is not what I want.
So, is there any way store the result inside a boolean value, and still keep the option as a simple flag?
To have an option with no value (passing means it is set true
) you should create it like this:
options_description desc;
desc.add_options()
("help", "produce help message")
To use notifier for such an option you can use the following type as semantics:
boost::program_options::bool_switch()
it can have true
or false
values and no value can be explicitly taken for this option from the command line. If the option is passed then the value is true
. If not passed - the value is false
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With