Repeated option groups with Commons CLI?

本秂侑毒 提交于 2019-12-11 03:17:31

问题


I have a specific set of requirements for parsing command line options. My intent is not unlike the Linux beep command, in which you can specify multiple beeps of different frequencies and durations. I just happen to be working with 4-bit colors.

Example of a valid input series:

-z 1 -r 5 -g 2 -b 12 -z 4 --color=ffe --zone=3 --color=8,8,4

The -z or --zone is the separator that starts a new option group. Colors may be specified with -r/g/b settings, or --color. I expect to handle parsing that myself.

Example of invalid input:

--zone=1 -r 12 -g 15 -z 3 -r 8 -g 6 -b 10 -b 18

This demonstrates exactly why I can't just work with an array of options. My program needs to be able to identify and alert that in between --zone=1 and the next zone, it did not find a -b, and that between -z 3 and the end of the parameters, it found two -b. Using the arrays provided by getOptionValues(), I would only see that there are two each of -r/g/b, and assume there was no problem, because they aren't tied to a parent or group of any sort.

I need to know if Commons CLI can handle repeating groups of options, or if I need to switch to another parser, or if I'm better off writing my own parser for the admittedly small variety of options.

来源:https://stackoverflow.com/questions/30114827/repeated-option-groups-with-commons-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!