使用这个非常好的命令行解析器 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 不应在输入列表中。