private static Command getCommandInstance(String cmdName, Configuration conf) { final CommandFactory commandFactory = new CommandFactory(conf); FsCommand.registerCommands(commandFactory); return commandFactory.getInstance(cmdName, conf); }
@Test @Ignore public void generateMethods() { final CommandFactory commandFactory = new CommandFactory(new Configuration()); FsCommand.registerCommands(commandFactory); final String[] names = commandFactory.getNames(); final String collect = Arrays.stream(names).map(item -> "\"" + item.replace("-", "") + "\"").collect(Collectors.joining(",")); System.out.println(collect); Arrays.stream(names).map(commandFactory::getInstance).forEach(item -> { String description = ""; final String[] sentences = item.getDescription().split("\\."); if (sentences.length == 0) { description = item.getDescription(); } else { description = sentences[0] + "."; } String cliCommand = String.format("@CliCommand(value = {\"%s\", \"hdfs dfs -%s\"}, help = \"%s\")", item.getCommandName(), item.getCommandName(), description); String content = String.format(" public String %s(\n" + " @CliOption(key = {\"\"}, help = \"%s\") String path\n" + " ) {\n" + " return runCommand(\"%s\", path);\n" + " }\n", item.getCommandName(), description, item.getCommandName()); System.out.println(cliCommand); System.out.println(content); System.out.println(); }); }