提高:: program_options - 它做一个确切的字符串命令行选项匹配? [英] boost::program_options - does it do an exact string matching for command line options?

查看:232
本文介绍了提高:: program_options - 它做一个确切的字符串命令行选项匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有似乎是一个问题的升压方式:: program_options的options_description匹配完成

There seems to be a problem the way boost::program_options's options_description matching is done.

int main(int argc, char* argv[])
{
    boost::program_options::options_description desc("CmdLine utility");
    desc.add_options()
        ("hel", "hel message")
        ("help", "produce help message")
        ("helps","helps message")       
    ;
    boost::program_options::variables_map vm;
    boost::program_options::store(boost::program_options::parse_command_line(argc, argv,desc), vm);
    boost::program_options::notify(vm);

    if(vm.count("help")) {
        std::cout << desc << std::endl;
    }
    if(vm.count("helps")) {
        std::cout << "helps..." << std::endl;
    }
    if(vm.count("hel")) {
        std::cout << "hel..." << std::endl;
    }
    return 0;
}

输出 -

C:\code>cmd.exe --helps
helps...
C:\code>cmd.exe --help
helps...
C:\code>cmd.exe --hel
helps...

输出的变化,如果我改变哪些选项是使用 add_options()调用添加的顺序。此外,它看起来像program_options没有做一个完整的命令字符串匹配,因此,即使你进入选项的子字符串,它会认为这是没有做一个完整的字符串比较有效的选项。如果这是一个boost :: program_options功能,有没有什么办法,迫使它做确切的字符串匹配,而不是与子串匹配干什么呢? (我用的升压版本1.42)

The output changes if I change the order in which options are added using add_options() call. Also it looks like program_options does not do a complete command string matching, so even if you enter a substring of the option, it will consider it as a valid option without doing a complete string comparison. If this is a boost::program_options feature, is there any way to force it to do exact string matching rather than doing it with substring matching ? (I am using Boost version 1.42)

推荐答案

默认情况下,program_option对allow_guessing样式位,这样子字符串匹配就足够了。你观察到,其中一个选项是匹配的命令行的preFIX,即使有,充分符合不同选项的行为,是一个错误。它固定于1.45。

By default, program_option has allow_guessing style bit on, so a substring match is sufficient. The behaviour you observe, where an option is matching a prefix of the command line, even when there's a different option that matches fully, is a bug. It's fixed in 1.45.

这篇关于提高:: program_options - 它做一个确切的字符串命令行选项匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆