public Object invoke(T command) throws InvocationException, SyntaxException { CommandInvoker<T, ?> invoker = getInvoker(); if (invoker != null) { return invoker.invoke(command); } else { return null; } }
org.crsh.cli.impl.invocation.CommandInvoker<Instance<T>,?> invoker = match.getInvoker();
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 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 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 Object invoke(T command) throws InvocationException, SyntaxException { CommandInvoker<T, ?> invoker = getInvoker(); if (invoker != null) { return invoker.invoke(command); } else { return null; } }
public Object invoke(Resolver resolver, T command) throws InvocationException, SyntaxException { CommandInvoker<T> invoker = getInvoker(); if (invoker != null) { return invoker.invoke(resolver, command); } else { return null; } }
public void testOption() throws Exception { // CommandDescriptor<Instance<A>> desc = CommandFactory.DEFAULT.create(A.class); HelpDescriptor<Instance<A>> helpDesc = new HelpDescriptor<Instance<A>>(desc); OptionDescriptor optionDesc = helpDesc.getOption("-h"); assertNotNull(optionDesc); OptionDescriptor foo = helpDesc.getOption("-f"); assertNotNull(foo); InvocationMatcher<Instance<A>> matcher = helpDesc.matcher(); // InvocationMatch<Instance<A>> match = matcher.parse("--help"); ParameterMatch<OptionDescriptor> helpMatch = match.getParameter(optionDesc); assertNotNull(helpMatch); CommandInvoker<Instance<A>, ?> invoker = match.getInvoker(); Help help = (Help)invoker.invoke(Util.wrap(new A())); assertNotNull(help); assertSame(desc, help.getDescriptor().getDelegate()); // match = matcher.parse(""); invoker = match.getInvoker(); invoker.invoke(Util.wrap(new A())); match = matcher.parse("-f foo_value bar"); invoker = match.getInvoker(); assertEquals("invoked:foo_value", invoker.invoke(Util.wrap(new A()))); }
public void testMain1() throws Exception { CommandDescriptor<Instance<b>> desc = CommandFactory.DEFAULT.create(b.class); HelpDescriptor<Instance<b>> helpDesc = new HelpDescriptor<Instance<b>>(desc); OptionDescriptor optionDesc = helpDesc.getOption("-h"); assertNotNull(optionDesc); InvocationMatcher<Instance<b>> matcher = helpDesc.matcher(); // InvocationMatch<Instance<b>> match = matcher.parse("--help"); ParameterMatch<OptionDescriptor> helpMatch = match.getParameter(optionDesc); assertNotNull(helpMatch); CommandInvoker<Instance<b>, ?> invoker = match.getInvoker(); Help help = (Help)invoker.invoke(Util.wrap(new b())); assertNotNull(help); CommandDescriptor mainDescriptor = help.getDescriptor(); assertEquals("b", mainDescriptor.getName()); assertSame(null, mainDescriptor.getOwner()); } }
org.crsh.cli.impl.invocation.CommandInvoker<Instance<T>,?> invoker = match.getInvoker();
org.crsh.cli.impl.invocation.CommandInvoker<Instance<T>,?> invoker = match.getInvoker();
public final CommandInvoker<?, ?> resolveInvoker(final InvocationMatch<CRaSHCommand> match) { final org.crsh.cli.impl.invocation.CommandInvoker invoker = match.getInvoker();