public ClassShellCommand(Class<T> clazz) throws IntrospectionException { CommandFactory factory = new CommandFactory(getClass().getClassLoader()); this.clazz = clazz; this.descriptor = HelpDescriptor.create(factory.create(clazz)); }
public GroovyScriptShellCommand(Class<T> clazz) throws IntrospectionException { // CommandFactory factory = new CommandFactory(getClass().getClassLoader()); boolean hasExplicitReturn; try { clazz.getDeclaredField(ScriptLastStatementTransformer.FIELD_NAME); hasExplicitReturn = true; } catch (NoSuchFieldException e) { hasExplicitReturn = false; } // this.clazz = clazz; this.descriptor = HelpDescriptor.create(factory.create(clazz)); this.hasExplicitReturn = hasExplicitReturn; }
private static <T> void handle(Class<T> commandClass, String line) throws Exception { ObjectCommandDescriptor<T> descriptor = CommandFactory.DEFAULT.create(commandClass); HelpDescriptor<Instance<T>> helpDescriptor = HelpDescriptor.create(descriptor); InvocationMatcher<Instance<T>> matcher = helpDescriptor.matcher(); InvocationMatch<Instance<T>> match = matcher.parse(line); final T instance = commandClass.newInstance(); Object o = match.invoke(Util.wrap(instance)); if (o != null) { System.out.println(o); } } }
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); }
public <C> void assertPreserveHelpInSubCommand2(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()). subordinate("sub"); CommandInvoker<Instance<C>, ?> invoker = match.getInvoker(); Object ret = invoker.invoke(Util.wrap(instance)); assertEquals("my help " + true, ret); } }
public <C> void assertPreserveHelpInSubCommand1(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. subordinate("sub"). 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); }
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 ClassShellCommand(Class<T> clazz) throws IntrospectionException { CommandFactory factory = new CommandFactory(getClass().getClassLoader()); this.clazz = clazz; this.descriptor = HelpDescriptor.create(factory.create(clazz)); }
public ClassShellCommand(Class<T> clazz) throws IntrospectionException { CommandFactory factory = new CommandFactory(getClass().getClassLoader()); this.clazz = clazz; this.descriptor = HelpDescriptor.create(factory.create(clazz)); }
protected CRaSHCommand() throws IntrospectionException { this.descriptor = HelpDescriptor.create(new CommandFactory(getClass().getClassLoader()).create(getClass())); this.unmatched = null; }
public GroovyScriptShellCommand(Class<T> clazz) throws IntrospectionException { // CommandFactory factory = new CommandFactory(getClass().getClassLoader()); boolean hasExplicitReturn; try { clazz.getDeclaredField(ScriptLastStatementTransformer.FIELD_NAME); hasExplicitReturn = true; } catch (NoSuchFieldException e) { hasExplicitReturn = false; } // this.clazz = clazz; this.descriptor = HelpDescriptor.create(factory.create(clazz)); this.hasExplicitReturn = hasExplicitReturn; }
public GroovyScriptShellCommand(Class<T> clazz) throws IntrospectionException { // CommandFactory factory = new CommandFactory(getClass().getClassLoader()); boolean hasExplicitReturn; try { clazz.getDeclaredField(ScriptLastStatementTransformer.FIELD_NAME); hasExplicitReturn = true; } catch (NoSuchFieldException e) { hasExplicitReturn = false; } // this.clazz = clazz; this.descriptor = HelpDescriptor.create(factory.create(clazz)); this.hasExplicitReturn = hasExplicitReturn; }
private static <T> void handle(Class<T> commandClass, String line) throws Exception { CommandDescriptorImpl<T> descriptor = CommandFactory.DEFAULT.create(commandClass); descriptor = HelpDescriptor.create(descriptor); InvocationMatcher<T> matcher = descriptor.invoker("main"); InvocationMatch<T> match = matcher.match(line); T instance = commandClass.newInstance(); Object o = match.invoke(instance); if (o != null) { System.out.println(o); } } }
private static <T> void handle(Class<T> commandClass, String line) throws Exception { ObjectCommandDescriptor<T> descriptor = CommandFactory.DEFAULT.create(commandClass); HelpDescriptor<Instance<T>> helpDescriptor = HelpDescriptor.create(descriptor); InvocationMatcher<Instance<T>> matcher = helpDescriptor.matcher(); InvocationMatch<Instance<T>> match = matcher.parse(line); final T instance = commandClass.newInstance(); Object o = match.invoke(Util.wrap(instance)); if (o != null) { System.out.println(o); } } }