我需要帮助选项 (-h) 和其他两个必需选项 (-u, -p) 共存..
private static Options buildOptions() {
Options options = new Options();
Option help = new Option("h", "help", false, "print this message");
Option user = OptionBuilder.hasArg()
.isRequired(true)
.withArgName("username")
.withDescription("use given user name for login")
.withLongOpt("user")
.create("u");
Option pass = OptionBuilder.hasArg()
.isRequired(true)
.withArgName("password")
.withDescription("use given password for login")
.withLongOpt("pass")
.create("p");
options.addOption(help);
options.addOption(user);
options.addOption(pass);
return options;
}
但是当我尝试在不提供所需参数的情况下解析 args 时,我收到 MissingOptionException。我正在寻找一种只能传递 -h 并且只能打印帮助的方法。