C++ 如何检查选项是否是带有CLI11的标志?
我正在使用CLI11库()解析程序的命令行参数 现在,我想将有关程序选项的信息打印到stdout。 似乎通过C++ 如何检查选项是否是带有CLI11的标志?,c++,command-line-arguments,C++,Command Line Arguments,我正在使用CLI11库()解析程序的命令行参数 现在,我想将有关程序选项的信息打印到stdout。 似乎通过App::add_flag(…)添加的标志也作为选项存储在内部,但我需要在输出中区分它们 如何确定哪个选项是标志? 以下是一个简化的示例: std::string file, bool myflag; CLI::App *command = app.add_subcommand("start", "Start the program"); command->add_option("
App::add_flag(…)
添加的标志也作为选项存储在内部,但我需要在输出中区分它们
如何确定哪个选项是标志?
以下是一个简化的示例:
std::string file, bool myflag;
CLI::App *command = app.add_subcommand("start", "Start the program");
command->add_option("file", file, "This is a file option")->required();
command->add_flag("--myflag", myflag);
print_description(command);
std::string打印描述(CLI::App*命令){
for(const auto&option:command->get_options()){
结果根据此问题:,函数Option::get\u expected\u min
将始终为标志返回0。
所以可以这样检查:
if(选项->获取预期值\u min()==0){
结果根据此问题:,函数Option::get\u expected\u min
将始终为标志返回0。
所以可以这样检查:
if(选项->获取预期值\u min()==0){
结果
std::string print_description(CLI::App* command) {
for (const auto &option : command->get_options()) {
result << R"(<option name=")" << option->get_name() << R"(" description=")" << option->get_description()
<< R"(" type=")";
if (/*option is a flag*/) {
result << "flag";
} else {
result << "option";
}
result << R"("/>)";
}
return result.str();
}