Reputation: 12894
I am using boost::program_options
to parse argv
. I expect both -c
and--config
boost::program_options::options_description description("Utility");
description.add_options()
("help,h", "display this message")
("config,c", boost::program_options::value<std::string>(), "Path to configuration file")
("config-type", boost::program_options::value<std::string>()->default_value("json"), "type of configuration file (json|xml)")
("verbose,v", boost::program_options::value<int>()->default_value(2), "verbosity(0 to 2)")
("thread,t",boost::program_options::value<int>()->default_value(0), (boost::format("Max Thread Count %1% to %2%(Processor cores of this machine) if not multi threaded") % 0 % boost::thread::hardware_concurrency()).str().c_str())
("action,a", boost::program_options::value<std::string>()->default_value("pack"), "action to perfoem (pack|unpack)");
boost::program_options::positional_options_description positional_description;
positional_description.add("action", -1);
boost::program_options::variables_map var_map;
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(description).positional(positional_description).style(boost::program_options::command_line_style::unix_style).run(), var_map);
boost::program_options::notify(var_map);
if(var_map.count("help")){
std::cout << description;
return 1;
}
if(var_map.count("config") < 1){
std::cout << "No Configuration file added" << std::endl;
return 1;
}
if(var_map.count("action") < 1){
std::cout << "Please specify an action to perfoem (pack|unpack)" << std::endl;
return 1;
}
but --config f
or --config=f
or--config="f"
doesn't work and prints No Configuration file added
though -c f
works.
also If I use --config
without any argument it throws exception saying required parameter is missing in 'config-type'
which already has a default parameter.
Upvotes: 2
Views: 644
Reputation: 684
Your problem seems to be exactly the same as described here: boost::program_options - does it do an exact string matching for command line options?
I am using ubuntu with boost 1.42 and ubuntu repo doesn't have a higher version. but is 1.42 that buggy ?
Yes.
You can workaround the problem by swapping the specification of --config
and --config-type
.
The cleaner solution is to upgrade Boost. Vladimir Prus in the mentioned SO answer says the bug is fixed in 1.45. From what you wrote I suppose you're using Ubuntu 11.04 (Natty Narwhal). You can do either of the following:
Upvotes: 1