我正在尝试使用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);
}