Method method = candidates.get(0); CommandLine cmd = new CommandLine(method); List<Object> list = cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args); return list == null ? null : list.get(0);
List<Object> results = cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args); @SuppressWarnings("unchecked") T result = (results == null || results.isEmpty()) ? null : (T) results.get(0); return result;
List<Object> results = cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args); @SuppressWarnings("unchecked") T result = (results == null || results.isEmpty()) ? null : (T) results.get(0); return result;
List<Object> results = cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args); @SuppressWarnings("unchecked") T result = (results == null || results.isEmpty()) ? null : (T) results.get(0); return result;
cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args);
return parseWithHandlers(handler, new DefaultExceptionHandler<R>(), args);
Method method = candidates.get(0); CommandLine cmd = new CommandLine(method); List<Object> list = cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args); return list == null ? null : list.get(0);
cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args);
@Test public void testOptionalListParameterShouldNotRememberValuesInCommandMethods() { @Command() class TestCommand { @Command(name="method") public String methodCommand(@Parameters(arity="0..*") List<String> methodValues) { return methodValues == null ? "null" : methodValues.toString(); } } CommandLine commandLine = new CommandLine(new TestCommand()); // problematic for @Command-method @Parameters List<Object> methodFirstExecutionResultWithParametersGiven = commandLine.parseWithHandlers( new RunLast(), new DefaultExceptionHandler<List<Object>>(), new String[] {"method","arg0", "arg1"}); List<Object> methodSecondExecutionResultWithoutParameters = commandLine.parseWithHandlers( new RunLast(), new DefaultExceptionHandler<List<Object>>(), new String[] {"method"}); assertEquals("[arg0, arg1]", methodFirstExecutionResultWithParametersGiven.get(0)); // fails, still "[arg0, arg1]" assertEquals("null", methodSecondExecutionResultWithoutParameters.get(0)); }
@Test public void testOptionalListParameterInCommandClass() { @Command() class TestCommand implements Callable<String> { @Parameters(arity="0..*") private List<String> values; public String call() throws Exception { return values == null ? "null" : values.toString(); } } // seems to be working for @Command-class @Parameters CommandLine commandLine = new CommandLine(new TestCommand()); List<Object> firstExecutionResultWithParametersGiven = commandLine.parseWithHandlers( new RunLast(), new DefaultExceptionHandler<List<Object>>(), new String[] {"arg0", "arg1"}); List<Object> secondExecutionResultWithoutParameters = commandLine.parseWithHandlers( new RunLast(), new DefaultExceptionHandler<List<Object>>(), new String[] {}); assertEquals("[arg0, arg1]", firstExecutionResultWithParametersGiven.get(0)); assertEquals("null", secondExecutionResultWithoutParameters.get(0)); }
CommandLine.Model.CommandSpec parseCommand(final String... args) { final TestPantheonCommand pantheonCommand = new TestPantheonCommand( mockLogger, mockBlockImporter, mockRunnerBuilder, mockControllerBuilder, mockSyncConfBuilder); // parse using Ansi.OFF to be able to assert on non formatted output results pantheonCommand.parse( new RunLast().useOut(outPrintStream).useAnsi(Ansi.OFF), new DefaultExceptionHandler<List<Object>>().useErr(errPrintStream).useAnsi(Ansi.OFF), args); return pantheonCommand.spec; }
/** Convenience method that returns {@code new DefaultExceptionHandler<List<Object>>()}. */ public static DefaultExceptionHandler<List<Object>> defaultExceptionHandler() { return new DefaultExceptionHandler<List<Object>>(); }
private DefaultExceptionHandler<List<Object>> defaultExceptionHandler() { return new DefaultExceptionHandler<List<Object>>(); }
return parseWithHandlers(handler, new DefaultExceptionHandler<R>(), args);
cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args);
cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args);
@Test public void testOptionalListParameterShouldNotRememberValuesInCommandMethods() { @Command() class TestCommand { @Command(name="method") public String methodCommand(@Parameters(arity="0..*") List<String> methodValues) { return methodValues == null ? "null" : methodValues.toString(); } } CommandLine commandLine = new CommandLine(new TestCommand()); // problematic for @Command-method @Parameters List<Object> methodFirstExecutionResultWithParametersGiven = commandLine.parseWithHandlers( new RunLast(), new DefaultExceptionHandler<List<Object>>(), new String[] {"method","arg0", "arg1"}); List<Object> methodSecondExecutionResultWithoutParameters = commandLine.parseWithHandlers( new RunLast(), new DefaultExceptionHandler<List<Object>>(), new String[] {"method"}); assertEquals("[arg0, arg1]", methodFirstExecutionResultWithParametersGiven.get(0)); // fails, still "[arg0, arg1]" assertEquals("null", methodSecondExecutionResultWithoutParameters.get(0)); }
@Test public void testOptionalListParameterInCommandClass() { @Command() class TestCommand implements Callable<String> { @Parameters(arity="0..*") private List<String> values; public String call() throws Exception { return values == null ? "null" : values.toString(); } } // seems to be working for @Command-class @Parameters CommandLine commandLine = new CommandLine(new TestCommand()); List<Object> firstExecutionResultWithParametersGiven = commandLine.parseWithHandlers( new RunLast(), new DefaultExceptionHandler<List<Object>>(), new String[] {"arg0", "arg1"}); List<Object> secondExecutionResultWithoutParameters = commandLine.parseWithHandlers( new RunLast(), new DefaultExceptionHandler<List<Object>>(), new String[] {}); assertEquals("[arg0, arg1]", firstExecutionResultWithParametersGiven.get(0)); assertEquals("null", secondExecutionResultWithoutParameters.get(0)); }
/** Convenience method that returns {@code new DefaultExceptionHandler<List<Object>>()}. */ public static DefaultExceptionHandler<List<Object>> defaultExceptionHandler() { return new DefaultExceptionHandler<List<Object>>(); }
private DefaultExceptionHandler<List<Object>> defaultExceptionHandler() { return new DefaultExceptionHandler<List<Object>>(); }