public ProducerCommandMatch(ClassShellCommand<T> shellCommand, CommandInvoker<Instance<T>, ?> invoker, Class<P> producedType) { super(shellCommand); // this.invoker = invoker; this.producedType = producedType; this.name = shellCommand.getDescriptor().getName(); }
/** * Print the full qualified name of the command. * * @param command the command * @param stream the output * @throws IOException any io exception */ protected void printFQN(CommandDescriptor<?> command, Appendable stream) throws IOException { CommandDescriptor<?> owner = command.getOwner(); if (owner != null) { printFQN(owner, stream); stream.append(' '); } stream.append(command.getName()); }
protected void printSubordinates(CommandDescriptor<?> command, Appendable stream) throws IOException { for (CommandDescriptor<?> subordinate : command.getSubordinates().values()) { stream.append(Util.MAN_TAB).append(subordinate.getName()); String methodText = subordinate.getDescription().getBestEffortMan(); if (methodText.length() > 0) { stream.append("\n"); Util.indent(Util.MAN_TAB_EXTRA, methodText, stream); } stream.append("\n\n"); } }
public void printDetailsSection(CommandDescriptor<?> command, Appendable stream) throws IOException { if (command.getSubordinates().isEmpty()) { List<String[]> tt = collectParametersTuples(command); int length = 0; for (String[] s : tt) { length = Math.max(s[0].length(), length); } String format = " %1$-" + length + "s %2$s\n"; for (String[] tuple : tt) { Formatter formatter = new Formatter(stream); formatter.format(format, tuple[0], tuple[1]); } } else { stream.append("The most commonly used ").append(command.getName()).append(" commands are:\n"); String format = " %1$-16s %2$s\n"; for (CommandDescriptor<?> subordinate : command.getSubordinates().values()) { Formatter formatter = new Formatter(stream); formatter.format(format, subordinate.getName(), subordinate.getUsage()); } } stream.append("\n\n"); } }
protected void printFQNWithOptions(CommandDescriptor<?> command, Appendable stream) throws IOException { CommandDescriptor<?> owner = command.getOwner(); if (owner != null) { printFQNWithOptions(owner, stream); stream.append(' '); } stream.append(command.getName()); for (OptionDescriptor option : command.getOptions()) { stream.append(' '); option.printUsage(stream); } }
@Override public CompletionMatch complete() throws CompletionException { org.crsh.cli.spi.Completion.Builder builder = org.crsh.cli.spi.Completion.builder(prefix); for (CommandDescriptor<?> m : descriptor.getSubordinates().values()) { String name = m.getName(); if (name.startsWith(prefix)) { builder.add(name.substring(prefix.length()), true); } } return new CompletionMatch(delimiter, builder.build()); } }
Command<?> cmd = crash.getCommand(s.getKey()); CommandDescriptor<?> desc = cmd.getDescriptor(); buffer.append("== ").append(desc.getName()).append("\n").append("\n"); buffer.append("----\n"); buffer.append(cmd.describe("", Format.MAN)); buffer.append("----\n"); for (CommandDescriptor<?> m : desc.getSubordinates().values()) { buffer.append("=== ").append(desc.getName()).append(" ").append(m.getName()).append("\n").append("\n"); buffer.append("----\n"); buffer.append(cmd.describe(m.getName(), Format.MAN)); buffer.append("----\n\n");
throw new CommandException(ErrorKind.EVALUATION, "Could not resolve command " + getDescriptor().getName(), e);
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 assertMethod(String name) { Event.Subordinate event = (Event.Subordinate)parser.next(); assertEquals(name, event.getDescriptor().getName()); }
public void testClassNameOverride() throws Exception { @Named("foo") class A { @Command public void main() {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); assertEquals("foo", c.getName()); }
public final CommandMatch<?, ?> resolveCommand(String line) throws CommandException { CommandDescriptor<T> descriptor = getDescriptor(); InvocationMatcher<T> analyzer = descriptor.matcher(); InvocationMatch<T> match; try { match = analyzer.parse(line); } catch (org.crsh.cli.impl.SyntaxException e) { throw new CommandException(ErrorKind.SYNTAX, "Syntax exception when evaluating "+ getDescriptor().getName(), e); } return resolve(match); }
/** * Returns a description of the command or null if none can be found. * * @param line the usage line * @param format the description format * @return the description */ public final String describe(String line, Format format) throws CommandException { CommandDescriptor<T> descriptor = getDescriptor(); InvocationMatcher<T> analyzer = descriptor.matcher(); InvocationMatch<T> match; try { match = analyzer.parse(line); } catch (org.crsh.cli.impl.SyntaxException e) { throw new CommandException(ErrorKind.SYNTAX, "Syntax exception when evaluating " + descriptor.getName(), e); } return describe(match, format); }
public void testMethodNameOverride() throws Exception { class A { @Named("foo") @Command public void bar() {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); assertEquals("A", c.getName()); assertNotNull(c.getSubordinate("foo")); assertEquals("foo", c.getSubordinate("foo").getName()); }
private <T> Test(Class<T> type, String s) { try { CommandDescriptor<Instance<T>> command = CommandFactory.DEFAULT.create(type); InvocationMatcher<Instance<T>> parser = command.matcher(); InvocationMatch<Instance<T>> match = parser.parse(s); // if (match.owner() == null) { this.sharedOptionMatches = new LinkedList<OptionMatch>(); this.optionMatches = new LinkedList<OptionMatch>(match.options()); this.argumentMatches = new LinkedList<ArgumentMatch>(match.arguments()); this.rest = match.getRest(); this.methodName = null; } else { this.sharedOptionMatches = new LinkedList<OptionMatch>(match.owner().options()); this.optionMatches = new LinkedList<OptionMatch>(match.options()); this.argumentMatches = new LinkedList<ArgumentMatch>(match.arguments()); this.rest = match.getRest(); this.methodName = match.getDescriptor().getName(); } } catch (Exception e) { AssertionFailedError afe = new AssertionFailedError(); afe.initCause(e); throw afe; } }
current = current.subordinate(((Event.Subordinate)event).getDescriptor().getName()); } else if (event instanceof Event.Argument) { Event.Argument argumentEvent = (Event.Argument)event;
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()); } }
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 final CommandMatch<?, ?> resolveCommand(String line) throws CommandException { CommandDescriptor<T> descriptor = getDescriptor(); InvocationMatcher<T> analyzer = descriptor.matcher(); InvocationMatch<T> match; try { match = analyzer.parse(line); } catch (org.crsh.cli.impl.SyntaxException e) { throw new CommandException(ErrorKind.SYNTAX, "Syntax exception when evaluating "+ getDescriptor().getName(), e); } return resolve(match); }