1

嘿,我正在使用Jcommander库来解析命令行参数。我的问题是 Jcommander 生成的使用消息的格式。这是使用函数的输出:

 Usage: mvnUploader [options]
 Options:
 * -d, --directory
     the directory of the artifacts to upload
   -h, --help
     print help message

我希望选项和描述在同一行

我的 args 类:

 public class OptionalArgs {

 @Parameter(names = {"-d", "--directory"}, required = true, description = 
            "the directory of the artifacts to upload")
 private String pathToArtifacts;

 @Parameter(names ={"-h", "--help"} , help = true, description = "print help 
                                                                  message")
 private boolean help = false;


 public String getPathToArtifacts() {
    return pathToArtifacts;
 }

 public boolean isHelp() {
    return help;
 }

}
4

1 回答 1

1

恐怕@RealSkeptic 是对的。困扰您的换行位于JCommander.java 的第 1210 行

 out.append(indent).append("  "
    + (parameter.required() ? "* " : "  ")
    + pd.getNames()
    + "\n");

恕我直言,自定义 impl。ofusage()需要付出很大的努力,因为您必须从JCommander.java. 引入可配置UsagePrinter类的拉取请求怎么样?

于 2017-06-25T13:41:03.523 回答