【发布时间】:2014-12-13 21:23:17
【问题描述】:
我正在尝试使用 boost(版本 1.46)允许“多空”选项。我的印象是启用 *disguise* 增强样式会允许这样的事情。鉴于此代码:
// Declare the supported options.
boost::program_options::options_description desc( "Allowed options" );
desc.add_options()
( "help,h", "produce help message" )
( "RunTimeE,rtttt", boost::program_options::value<std::string>(), "RunTimeE Version" )
;
boost::program_options::variables_map vm;
boost::program_options::store( boost::program_options::command_line_parser( argc, argv )
.options( desc )
.style( boost::program_options::command_line_style::unix_style
| boost::program_options::command_line_style::allow_long_disguise )
.run(),
vm );
boost::program_options::notify( vm );
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
if (vm.count("RunTimeE")) {
cout << vm["RunTimeE"].as<std::string>() << endl;
return 1;
}
将产生:
./output --help
Allowed options:
-h [ --help ] produce help message
-r [ --RunTimeE ] arg RunTimeE Version
但我希望它产生:
./output --help
Allowed options:
-h [ --help ] produce help message
-rtttt [ --RunTimeE ] arg RunTimeE Version
有人可以帮忙吗?
谢谢。
【问题讨论】:
-
如果不写你自己的custom parser,我不确定这是否可行。您正在指定一个长选项
RunTimeE和一个短选项rtttt,但根据定义,短选项只有一个字符。您可以通过指定allow_long_disguise来使用带有单个破折号的长选项,但我认为不允许您有两个长选项。事实上,在多头和空头之间拥有两个多头期权有什么意义?
标签: c++ boost arguments options boost-program-options