最好使用另一个选项(-d)来识别对用户来说更直观的目录。
或者,以下代码演示如何获取剩余的参数列表
public static void main(final String[] args) {
final CommandLineParser parser = new BasicParser();
final Options options = new Options();
options.addOption("a", "opta", true, "Option A");
options.addOption("b", "optb", true, "Option B");
final CommandLine commandLine = parser.parse(options, args);
final String optionA = getOption('a', commandLine);
final String optionB = getOption('b', commandLine);
final String[] remainingArguments = commandLine.getArgs();
System.out.println(String.format("OptionA: %s, OptionB: %s", optionA, optionB));
System.out.println("Remaining arguments: " + Arrays.toString(remainingArguments));
}
public static String getOption(final char option, final CommandLine commandLine) {
if (commandLine.hasOption(option)) {
return commandLine.getOptionValue(option);
}
return StringUtils.EMPTY;
}