public final int getDepth() { CommandDescriptor<T> owner = getOwner(); return owner == null ? 0 : 1 + owner.getDepth(); }
/** * 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 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); } }
/** * Find an command option by its name, this will look through the command hierarchy. * * @param name the option name * @return the option or null */ public final OptionDescriptor resolveOption(String name) { OptionDescriptor option = getOption(name); if (option == null) { CommandDescriptor<T> owner = getOwner(); if (owner != null) { option = owner.resolveOption(name); } } return option; }
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; }
private List<String[]> collectParametersTuples(CommandDescriptor<?> command) throws IOException { CommandDescriptor<?> owner = command.getOwner(); List<String[]> tuples; Collection<? extends ParameterDescriptor> parameters; if (owner != null) { tuples = collectParametersTuples(owner); parameters = command.getOptions(); } else { tuples = new ArrayList<String[]>(); parameters = command.getParameters(); } for (ParameterDescriptor parameter : parameters) { StringBuilder sb = new StringBuilder(); parameter.printUsage(sb); String usage = sb.toString(); tuples.add(new String[]{usage, parameter.getUsage()}); } return tuples; }
public final int getDepth() { CommandDescriptor<T> owner = getOwner(); return owner == null ? 0 : 1 + owner.getDepth(); }
public final int getDepth() { CommandDescriptor<T> owner = getOwner(); return owner == null ? 0 : 1 + owner.getDepth(); }
/** * 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 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); } }
/** * Find an command option by its name, this will look through the command hierarchy. * * @param name the option name * @return the option or null */ public final OptionDescriptor resolveOption(String name) { OptionDescriptor option = getOption(name); if (option == null) { CommandDescriptor<T> owner = getOwner(); if (owner != null) { option = owner.resolveOption(name); } } return option; }
/** * Find an command option by its name, this will look through the command hierarchy. * * @param name the option name * @return the option or null */ public final OptionDescriptor findOption(String name) { OptionDescriptor option = getOption(name); if (option == null) { CommandDescriptor<T> owner = getOwner(); if (owner != null) { option = owner.findOption(name); } } return option; }
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()); } }
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; }
private List<String[]> collectParametersTuples(CommandDescriptor<?> command) throws IOException { CommandDescriptor<?> owner = command.getOwner(); List<String[]> tuples; Collection<? extends ParameterDescriptor> parameters; if (owner != null) { tuples = collectParametersTuples(owner); parameters = command.getOptions(); } else { tuples = new ArrayList<String[]>(); parameters = command.getParameters(); } for (ParameterDescriptor parameter : parameters) { StringBuilder sb = new StringBuilder(); parameter.printUsage(sb); String usage = sb.toString(); tuples.add(new String[]{usage, parameter.getUsage()}); } return tuples; }
CommandDescriptor<T> owner = getOwner(); int length = 0; List<String> parameterUsages = new ArrayList<String>();
CommandDescriptor<T> owner = getOwner();