1

使用这个非常好的命令行解析器 Argo(仅标头 C++ 库)我遇到了一个小问题。见:https ://github.com/phforest/Argo

当未找到选项时,Argo 返回:'错误:未知选项',但当参数位于已知参数后面时则不会。

编译下面的代码:(inc是argo头文件的位置) c++ test.cpp -I inc --std=c++11

#include <iostream>
int main(int argc, char **argv)
{
        argo::Configuration pcnfg;
        std::vector<std::string>    input_texts;
        pcnfg.program.name = { "wow", "EyeOnText WoWoolConsole" };
        pcnfg.program.version = { 1, 1, 1 };

        argo::Arguments args(pcnfg);
        args.add(argo::handler::Option("input-text", "i", input_texts).help("Input text to process."));

        const auto result = args.parse(argc, argv);
        switch (result.status)
        {
            case argo::ReturnCode::Error: std::cerr << "Error: " << result.message << std::endl; return 1;
            case argo::ReturnCode::SuccessAndAbort: return 0;
            default: break;
        }

        for ( auto const & input : input_texts )
        {
            std::cout << "- " << input << std::endl;
        }
    return 0;
}

运行:./a.out --other -i "test" 错误:未知选项 '--other' 没关系

运行:./a.out -i "test" --other - test - --other

--other 不应在输入列表中。

4

1 回答 1

0

(免责声明:我是图书馆的开发者)

我认为这在更新的版本中得到了解决。至少,使用提供的代码,我得到了预期的输出(两次“未知选项”错误)。如果没有解决,我们可以使用https://gitlab.com/dgrine/Argo/issues上的错误跟踪器来处理它

于 2019-07-29T10:02:30.940 回答