for (String name : commandFactory.getNames()) { Command instance = commandFactory.getInstance(name); if (!instance.isDeprecated()) {
@Override public String[] getNames() { return commandFactory.getNames(); }
@Test public void testRegistration() { assertArrayEquals(new String []{}, factory.getNames()); factory.registerCommands(TestRegistrar.class); String [] names = factory.getNames(); assertArrayEquals(new String []{"tc1", "tc2", "tc2.1"}, names); factory.addClass(TestCommand3.class, "tc3"); names = factory.getNames(); assertArrayEquals(new String []{"tc1", "tc2", "tc2.1", "tc3"}, names); }
for (String name : commandFactory.getNames()) { Command instance = commandFactory.getInstance(name); if (!instance.isDeprecated()) {
for (String name : commandFactory.getNames()) { Command instance = commandFactory.getInstance(name); if (!instance.isDeprecated()) {
@Test public void testRegistration() { assertArrayEquals(new String []{}, factory.getNames()); factory.registerCommands(TestRegistrar.class); String [] names = factory.getNames(); assertArrayEquals(new String []{"tc1", "tc2", "tc2.1"}, names); factory.addClass(TestCommand3.class, "tc3"); names = factory.getNames(); assertArrayEquals(new String []{"tc1", "tc2", "tc2.1", "tc3"}, names); }
for (String name : commandFactory.getNames()) { Command instance = commandFactory.getInstance(name); if (!instance.isDeprecated()) {
for (String name : commandFactory.getNames()) { Command instance = commandFactory.getInstance(name); if (!instance.isDeprecated()) {
@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(); }); }