Java – args4j: how do I manually sort options in usage?

In args4j, I define the following options:

@Option(name="-host",usage="host to connect")
@Option(name="-port",usage="port of the host")
@Option(name="-idle",usage="idle")

However, when help is displayed, args4j is always used alphabetically for printing

-host - host to connect
-idle - idle
-port - port to connect

This is inconvenient because I want to show the mandatory option first In addition, I want to set the order of options myself, because some options (such as host and port) should be used together

How do I control the order of options in args4j?

I found the same question three years ago, but I didn't answer it http://markmail.org/message/xce6vitw6miywtos

Solution

You can't use the current args4j (at least as far as I know) – but since it's open source, I encourage you to implement it yourself and try to get a patch in the new version of the source code

From: org kohsuke. args4j. CmdLineParser:

// for display purposes,we like the arguments in argument order,but the options in    alphabetical order
     Collections.sort(options,new Comparator<OptionHandler>() {
        public int compare(OptionHandler o1,OptionHandler o2) {
            return o1.option.toString().compareTo(o2.option.toString());
        } 
    });
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>