我正在创建一个命令行解析器,并希望支持选项捆绑。但是,我不确定如何处理可能出现的歧义和冲突。请考虑以下三种情况:我应该如何解析捆绑的命令行选项和歧义?
1.
-I accepts a string
"-Iinclude" -> Would be parsed as "-I include"
2.
-I accepts a string
-n accepts an integer
"-Iincluden10" -> Would be parsed as "-I include -n 10" because the 'cluden10' after the first occurrence of 'n' cannot be parsed as an integer.
3.
-I accepts a string
-n accepts an integer
-c accepts a string
"-Iin10clude" -> ??? What now ???
如何处理最后一个字符串?有分析它的多种方式,所以我只是把一个错误,通知用户有关歧义或做我选择解析产生最,即作为字符串“-I我-n 10 -c路得”?
我找不到任何详细的约定网上,但个人,我会将此作为一个多义性错误。
感谢很多有趣的见解和建议。我将尝试更多地调查POSIX/Gnu指南,然后决定您提到的一种简单的现有实践。 – NordCoder