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 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 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"); } }
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 void print(CommandDescriptor<?> command, Appendable stream) throws IOException { printUsageSection(command, stream); printDetailsSection(command, stream); }
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 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"); } }
public void print(CommandDescriptor<?> command, Appendable stream) throws IOException { printUsageSection(command, stream); printDetailsSection(command, stream); }