protected boolean printOptions(boolean printed, CommandDescriptor<?> command, Appendable stream) throws IOException { CommandDescriptor<?> owner = command.getOwner(); if (owner != null) { printed = printOptions(printed, owner, stream); } for (OptionDescriptor option : command.getOptions()) { printed = printParameter(printed, option, stream); } return printed; }
protected boolean printParameters(boolean printed, CommandDescriptor<?> command, Appendable stream) throws IOException { for (ArgumentDescriptor argument : command.getArguments()) { printed = printParameter(printed, argument, stream); } return printed; }
public void print(CommandDescriptor<?> command, Appendable stream) throws IOException { printNameSection(command, stream); printSynopsisSection(command, stream); printDescriptionSection(command, stream); printParametersSection(command, stream); }
public void testParameterMetaDescription1() throws Exception { class A { @Command void m(@Foo String s) {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); CommandDescriptor<Instance<A>> m = c.getSubordinate("m"); OptionDescriptor a = m.getOption("-a"); assertEquals("foo_usage", a.getUsage()); assertEquals("foo_usage", a.getDescription().getUsage()); assertEquals("foo_man", a.getDescription().getMan()); }
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); } }
public void testParameterMetaDescription2() throws Exception { class A { @Command void m(@Bar String s) {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); CommandDescriptor<Instance<A>> m = c.getSubordinate("m"); OptionDescriptor a = m.getOption("-a"); assertEquals("", a.getUsage()); assertEquals(new Description(), a.getDescription()); }
public void printUsageSection(CommandDescriptor<?> command, Appendable stream) throws IOException { stream.append("usage: "); printFQNWithOptions(command, stream); if (command.getSubordinates().size() > 0) { stream.append(" COMMAND [ARGS]"); } else { for (ArgumentDescriptor argument : command.getArguments()) { stream.append(' '); argument.printUsage(stream); } } stream.append("\n\n"); }
public void testNoDescription() throws Exception { class A { } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); assertEquals("", c.getUsage()); assertEquals(new Description(), c.getDescription()); }
public void printParametersSection(CommandDescriptor<?> command, Appendable stream) throws IOException { boolean printed = printOptions(false, command, stream); if (command.getSubordinates().size() > 0) { stream.append("COMMANDS\n"); printSubordinates(command, stream); } else { printParameters(printed, command, stream); } }
/** * Returns the command usage, shortcut for invoking <code>getDescription().getUsage()</code> on this * object. * * @return the command usage */ public final String getUsage() { return description != null ? description.getUsage() : ""; }
public final void printMan(Appendable to) throws IOException { print(Format.MAN, to); }
public final boolean isMultiValued() { return getMultiplicity() == Multiplicity.MULTI; }
public void print(CommandDescriptor<?> command, Appendable stream) throws IOException { printUsageSection(command, stream); printDetailsSection(command, stream); }
public final void print(Format format, Appendable to) throws IOException { format.print(this, to); }
public CommandInvoker<T, ?> getInvoker() { return descriptor.getInvoker(this); }
public void testParameterMetaDescription3() throws Exception { class A { @Command void m( @Usage("option_usage") @Foo String s) {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); CommandDescriptor<Instance<A>> m = c.getSubordinate("m"); OptionDescriptor a = m.getOption("-a"); assertEquals("option_usage", a.getUsage()); assertEquals("option_usage", a.getDescription().getUsage()); assertEquals("foo_man", a.getDescription().getMan()); } }
public final String getUsage() { return description != null ? description.getUsage() : ""; }
public final void printUsage(Appendable to) throws IOException { print(Format.USAGE, to); }
public final boolean isSingleValued() { return getMultiplicity() == Multiplicity.SINGLE; }