getopt_long()/getopt() 具有重复的选项输入
我刚刚了解这两个功能。一直在互联网上搜索以了解它们的用法。发现一件对于解析命令行选项输入非常重要的事情,但没有讨论。
在这种情况下,如果输入重复的选项,两个函数都无法做任何处理。我想知道是否有任何 lib 函数可以用于此目的。
如果我必须自己处理的话。我想到的方法是将短选项收集到一个数组中,并在数组中找到相同的选项。
有更好的方法吗?
I just got to know both functions. Have been searching internet to learn their usage. Found one thing which is very important to parse the command line option input, but not discussed.
Is such a case, if duplicated options are typed in, both functions can not do anything to handle it. I was wondering if there is any lib function to use for this.
If I have to handle it myself. The way in my mind is to collection short option into an array and find identical ones in the array.
Any better way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想对重复选项执行一些特殊操作,您可以在选项处理代码中管理状态。
像
-v|--verbose
这样的东西可以重复以获得额外的详细程度,并且 vebosity 处理代码是(对于可以使用应该使用的参数重复的选项,加载一个列表或类似的列表)。
如果您不想重复做任何特殊的事情,只需每次设置该值
,如果您想检测重复
If you want to do something special with duplicate options, you can manage state in the option handling code.
Something like
-v|--verbose
can be repeated for additional verboseness, and the vebosity handling code is(for options that can be repeated with arguments which should all be used, load up a list or some such).
If you don't want repeats to do anything special just set the value every time
and if you want to detect repeats