Apache Commons CLI - 订购帮助选项? [英] Apache Commons CLI - ordering help options?
问题描述
我使用的是 Apache Commons CLI.默认情况下,它按键按字母顺序排列命令行上的帮助选项.所以,出现的是:
I'm using the Apache Commons CLI. By default it orders help options on the command line alphabetically by key. So, what appears is:
-csv
-ip
-msisdn
-xml
但我想按如下顺序排列它们:
But I want to order them as follows:
-csv
-xml
-ip
-msisdn
我知道有一个 OptionFormatter 类您可以使用并传递给 HelpFormatter,但是在上面看不到任何关于如何将它用于我的目的的示例 (http://www.marko.homeunix.org/programming/java/commons-cli/api/org/apache/commons/cli/HelpFormatter.OptionComparator.html).
I know that there is a OptionFormatter class you can use and pass to the HelpFormatter, but can't see any examples on how to use it for my purposes above (http://www.marko.homeunix.org/programming/java/commons-cli/api/org/apache/commons/cli/HelpFormatter.OptionComparator.html).
只是想知道有人做过类似的事情吗?
Just wondering has anyone done anything similar?
谢谢
推荐答案
目前不支持.但它是开源的,所以你知道该怎么做...
Currently it is not supported. But it is an open source so, you know what to do...
来自源代码:
private static class OptionComparator
implements Comparator {
/**
* <p>Compares its two arguments for order. Returns a negative
* integer, zero, or a positive integer as the first argument
* is less than, equal to, or greater than the second.</p>
*
* @param o1 The first Option to be compared.
* @param o2 The second Option to be compared.
*
* @return a negative integer, zero, or a positive integer as
* the first argument is less than, equal to, or greater than the
* second.
*/
public int compare(Object o1, Object o2)
{
Option opt1 = (Option)o1;
Option opt2 = (Option)o2;
return opt1.getKey().compareToIgnoreCase(opt2.getKey());
}
}
您可以覆盖默认比较器并定义您想要的顺序.
You can override the default comparator and define the order you want.
这篇关于Apache Commons CLI - 订购帮助选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!