Very simple example:
#include <string>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main(int argc, char* argv[])
{
po::options_description recipients("Recipient(s)");
recipients.add_options()
("csv", po::value<std::string>(), "" )
("csv_name", po::value<unsigned>(), "" )
;
po::options_description cmdline_options;
cmdline_options.add(recipients);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(cmdline_options).run(), vm);
po::notify(vm);
return 0;
}
And some tests:
>Test --csv test
in option 'csv_name': invalid option value
>Test --csv_name test
in option 'csv_name': invalid option value
>Test --csv_name 0
>Test --csv text
in option 'csv_name': invalid option value
>Test --csv 0
>Test --csv_name 0
>Test --csv_name 0 --csv text
multiple occurrences
Looks like that boost::program_option threats parameter "csv" as "csv_name".
Is it a feature or bug?
Yes, this is a "feature" due to default options parsing style. Try with short options, like:
recipients.add_options()
("csv,c", po::value<std::string>(), "" )
("csv_name,C", po::value<unsigned>(), "" )
;
Or play with the basic_command_line_parser::style(int)
method. I haven't tried this, so YMMV.
I am afraid this is a bug. But, it should be fixed in 1.42 -- which version did you try with?
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