throw new UnknownCommandException(); TraceScope scope = tracer.newScope(instance.getCommandName()); if (scope.getSpan() != null) { String args = StringUtils.join(" ", argv);
/** handle IOException */ private void handleIOException(IOException e) { String content = e.getLocalizedMessage(); if (e instanceof RemoteException) { int eol = content.indexOf('\n'); if (eol>=0) { content = content.substring(0, eol); } } System.err.println(getCommandName() + ": " + content); } }
content = content.substring(0, eol); System.err.println(getCommandName() + ": " + content); } catch (IOException e) { exitCode = -1; System.err.println(getCommandName() + ": " + e.getLocalizedMessage());
@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(); }); }
throw new UnknownCommandException(); TraceScope scope = tracer.newScope(instance.getCommandName()); if (scope.getSpan() != null) { String args = StringUtils.join(" ", argv);
@Test public void testGetInstances() { factory.registerCommands(TestRegistrar.class); Command instance; instance = factory.getInstance("blarg"); assertNull(instance); instance = factory.getInstance("tc1"); assertNotNull(instance); assertEquals(TestCommand1.class, instance.getClass()); assertEquals("tc1", instance.getCommandName()); instance = factory.getInstance("tc2"); assertNotNull(instance); assertEquals(TestCommand2.class, instance.getClass()); assertEquals("tc2", instance.getCommandName()); instance = factory.getInstance("tc2.1"); assertNotNull(instance); assertEquals(TestCommand2.class, instance.getClass()); assertEquals("tc2.1", instance.getCommandName()); }
@Test public void testGetInstances() { factory.registerCommands(TestRegistrar.class); Command instance; instance = factory.getInstance("blarg"); assertNull(instance); instance = factory.getInstance("tc1"); assertNotNull(instance); assertEquals(TestCommand1.class, instance.getClass()); assertEquals("tc1", instance.getCommandName()); instance = factory.getInstance("tc2"); assertNotNull(instance); assertEquals(TestCommand2.class, instance.getClass()); assertEquals("tc2", instance.getCommandName()); instance = factory.getInstance("tc2.1"); assertNotNull(instance); assertEquals(TestCommand2.class, instance.getClass()); assertEquals("tc2.1", instance.getCommandName()); }