我有以下参数添加到CLI
-sbx
-CSWConfig
-stripInfo
-modelSources
-catchArchive
-swSupplierName
-modelsSWExchnage如何保留帮助部分中的参数排序?
但同时显示帮助它显示这些排序顺序(如下图所示),我不想要的选项,我希望所有的选项,因为他们被添加。
-CatchArchive
-CSWConfig
-modelSources
-sbx
-stripInfo
-swSupplierName
我读这一个link但我无法保留的排序,而显示帮助内容。
private void print_help() {
String CONST_STR_CLI_INFO = "ercli.exe custzip";
HelpFormatter formatter = new HelpFormatter();
formatter.setOptionComparator(new Comparator() {
@Override
public int compare(Object o1, Object o2) {
Option op1=(Option) o1;
Option op2=(Option) o2;
return //what to do here?
}
});
formatter.printHelp(CONST_STR_CLI_INFO, null, options, "", true);
}
在[链接](http://stackoverflow.com/questions/11741625/apache-commons-cli-ordering-help-options/12449193#12449193)第4个答案给了回报opt1.getKey()。与compareToIgnoreCase (opt2.getKey());你会得到的。 – 2014-10-08 12:39:04