public Object invoke(T command) throws InvocationException, SyntaxException { CommandInvoker<T, ?> invoker = getInvoker(); if (invoker != null) { return invoker.invoke(command); } else { return null; } }
public void testFoo() throws Exception { CommandDescriptor<Instance<A>> desc = HelpDescriptor.create(CommandFactory.DEFAULT.create(A.class)); InvocationMatcher<Instance<A>> matcher = desc.matcher(); InvocationMatch<Instance<A>> match = matcher.options(Collections.<String, List<?>>singletonMap("h", Collections.singletonList(Boolean.TRUE))).arguments(Collections.emptyList()); CommandInvoker<Instance<A>, ?> invoker = match.getInvoker(); Object ret = invoker.invoke(Util.wrap(new A())); assertTrue(ret instanceof Help); assertEquals(Help.class, invoker.getReturnType()); }
public PipeCommandMatch(ClassShellCommand<T> baseShellCommand, CommandInvoker<Instance<T>, PC> invoker) { super(baseShellCommand); this.invoker = invoker; ret = invoker.getGenericReturnType(); consumedType = (Class<C>)Utils.resolveToClass(ret, Pipe.class, 0); producedType = (Class<P>)Utils.resolveToClass(ret, Pipe.class, 1); name = baseShellCommand.getDescriptor().getName(); }
public void open2(final CommandContext<P> consumer) throws CommandException { // invocationContext = new InvocationContextImpl<P>(consumer); // Push context command.pushContext(invocationContext); // Set the unmatched part command.unmatched = invoker.getMatch().getRest(); // PC ret; try { ret = invoker.invoke(this); } catch (org.crsh.cli.impl.SyntaxException e) { throw new CommandException(ErrorKind.SYNTAX, "Syntax exception when executing command " + name, e); } catch (InvocationException e) { throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e.getCause()); } // It's a pipe command if (ret != null) { real = ret; try { real.open(invocationContext); } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e); } } }
if (PipeCommand.class.isAssignableFrom(invoker.getReturnType())) { Type ret = invoker.getGenericReturnType(); consumedType = TypeResolver.resolveToClass(ret, PipeCommand.class, 0); producedType = TypeResolver.resolveToClass(ret, PipeCommand.class, 1); consumedType = Void.class; producedType = Object.class; Class<?>[] parameterTypes = invoker.getParameterTypes(); for (int i = 0;i < parameterTypes.length;i++) { Class<?> parameterType = parameterTypes[i]; if (InvocationContext.class.isAssignableFrom(parameterType)) { Type contextGenericParameterType = invoker.getGenericParameterTypes()[i]; producedType = TypeResolver.resolveToClass(contextGenericParameterType, InvocationContext.class, 0); break;
if (Pipe.class.isAssignableFrom(invoker.getReturnType())) { org.crsh.cli.impl.invocation.CommandInvoker tmp = invoker; return getPipeInvoker(tmp); if (void.class.equals(invoker.getReturnType())) { producedType = Object.class; } else { producedType = invoker.getReturnType();
public void open2(final CommandContext<P> consumer) { invocationContext = new InvocationContextImpl<P>(consumer); command.pushContext(invocationContext); command.unmatched = invoker.getMatch().getRest(); }
@Override public Type[] getGenericParameterTypes() { return invoker != null ? invoker.getGenericParameterTypes() : new Type[0]; }
@Override public Class<?>[] getParameterTypes() { return invoker != null ? invoker.getParameterTypes() : new Class[0]; }
public void open2(final CommandContext<P> consumer) throws CommandException { // invocationContext = new InvocationContextImpl<P>(consumer); // Push context command.pushContext(invocationContext); // Set the unmatched part command.unmatched = invoker.getMatch().getRest(); // PC ret; try { ret = invoker.invoke(this); } catch (org.crsh.cli.impl.SyntaxException e) { throw new CommandException(ErrorKind.SYNTAX, "Syntax exception when executing command " + name, e); } catch (InvocationException e) { throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e.getCause()); } // It's a pipe command if (ret != null) { real = ret; try { real.open(invocationContext); } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e); } } }
@Override public Class<?> getReturnType() { return invoker != null ? invoker.getReturnType() : Void.class; }
public void open2(final CommandContext<P> consumer) { invocationContext = new InvocationContextImpl<P>(consumer); command.pushContext(invocationContext); command.unmatched = invoker.getMatch().getRest(); }
Object ret; try { ret = invoker.invoke(this);
public void open2(final CommandContext<P> consumer) throws CommandException { // invocationContext = new InvocationContextImpl<P>(consumer); // Push context command.pushContext(invocationContext); // Set the unmatched part command.unmatched = invoker.getMatch().getRest(); // PC ret; try { ret = invoker.invoke(this); } catch (org.crsh.cli.impl.SyntaxException e) { throw new CommandException(ErrorKind.SYNTAX, "Syntax exception when executing command " + name, e); } catch (InvocationException e) { throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e.getCause()); } // It's a pipe command if (ret != null) { real = ret; try { real.open(invocationContext); } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e); } } }
if (Pipe.class.isAssignableFrom(invoker.getReturnType())) { org.crsh.cli.impl.invocation.CommandInvoker tmp = invoker; return getPipeInvoker(tmp); if (void.class.equals(invoker.getReturnType())) { producedType = Object.class; } else { producedType = invoker.getReturnType();
@Override public Type getGenericReturnType() { return invoker != null ? invoker.getGenericReturnType() : Void.class; }
public void open2(final CommandContext<P> consumer) { invocationContext = new InvocationContextImpl<P>(consumer); command.pushContext(invocationContext); command.unmatched = invoker.getMatch().getRest(); }
public <C> void assertPreserveHelp(Class<C> clazz, C instance, String option) throws Exception { CommandDescriptor<Instance<C>> desc = HelpDescriptor.create(CommandFactory.DEFAULT.create(clazz)); InvocationMatcher<Instance<C>> matcher = desc.matcher(); InvocationMatch<Instance<C>> match = matcher.options(Collections.<String, List<?>>singletonMap(option, Collections.singletonList(Boolean.TRUE))).arguments(Collections.emptyList()); CommandInvoker<Instance<C>, ?> invoker = match.getInvoker(); Object ret = invoker.invoke(Util.wrap(instance)); assertEquals("my help " + true, ret); }
if (Pipe.class.isAssignableFrom(invoker.getReturnType())) { org.crsh.cli.impl.invocation.CommandInvoker tmp = invoker; return getPipeInvoker(tmp); if (void.class.equals(invoker.getReturnType())) { producedType = Object.class; } else { producedType = invoker.getReturnType();
public PipeCommandMatch(ClassShellCommand<T> baseShellCommand, CommandInvoker<Instance<T>, PC> invoker) { super(baseShellCommand); this.invoker = invoker; ret = invoker.getGenericReturnType(); consumedType = (Class<C>)Utils.resolveToClass(ret, Pipe.class, 0); producedType = (Class<P>)Utils.resolveToClass(ret, Pipe.class, 1); name = baseShellCommand.getDescriptor().getName(); }