对于每个命令,我都有一个实现特定接口的具体类。例如:
public class FooCommand implements Command{
@Parameter(names = {"-?","--help"}, description = "display this help",help = true)
private boolean helpRequested = false;
...
}
这是我得到的使用信息:
Usage: foo-command [options]
Options:
-?, --help
display this help
如何将描述添加到命令(而不是选项)。例如我想得到这样的使用信息:
Usage: foo-command [options] - This command is used as base foo
Options:
-?, --help
display this help
编辑我有 foo-command、boo-command、lala-command。但是,所有这些命令都是独立的,并且不在一个主命令中(换句话说,这不像 git clone ...)。这就是我使用的方式
JCommander jCommander=new JCommander(command, args);
jCommander.setProgramName(commandName);//for example foo-command
StringBuilder builder=new StringBuilder();
jCommander.usage(builder);