@Override public CommandParserContext parse( final CommandMetadata command, final Queue<String> tokens, final CommandParserContext ctx) { try { OptionMetadata option = command.getOrderedOptionByIndex(ctx.getOrderedParamCount()); if (option.isVarargs()) { List<String> args = new ArrayList<String>(); String lastToken = null; // gobble unless we hit a named token while (!tokens.isEmpty()) { lastToken = tokens.peek(); if (lastToken.startsWith("-") && command.hasOption(lastToken.replaceAll("^--?", ""))) { break; } lastToken = tokens.remove(); lastToken = Strings.stripQuotes(lastToken); args.add(lastToken); } ctx.put(option, args.toArray(new String[args.size()]), Strings.stripQuotes(lastToken)); ctx.incrementParmCount(); } } catch (IllegalArgumentException e) { ctx.addWarning( "The command [" + command + "] takes [" + command.getNumOrderedOptions() + "] unnamed argument(s), but found [" + (ctx.getOrderedParamCount() + 1) + "]."); } return ctx; }
private String formatSourcedError(final CommandMetadata cmd) { String out; if (cmd != null) { out = cmd.getParent().getName(); if (!cmd.isDefault()) out += " " + cmd.getName(); out = "[" + out + "] "; } else out = ""; return out; }