我有以下參數添加到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