boost::program_options
解析に使用していますargv
。私は両方を期待し-c
、--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;
}
しかし、--config f
または--config=f
または--config="f"
機能せず、機能しますが印刷さNo Configuration file added
れます-c f
。
また--config
、引数なしで使用するとrequired parameter is missing in 'config-type'
、すでにデフォルトのパラメーターがあるという例外がスローされます。