我正在尝试使用 apache commons-cli 来解析传递给 java 命令行实用程序的命令行参数。
有没有办法让“-r”和“-R”都表示“递归子目录”而不向解析器添加 2 个选项(这会弄乱使用打印输出)。
一些代码:
Options options = new Options();
options.addOption("r", "recurse", false,"recurse subdirectories");
CommandLineParser parser = new BasicParser();
CommandLine cmd = null;
try {
cmd = parser.parse( options, args);
} catch (ParseException e) {
e.printStackTrace();
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("readfiles", options);
}