/** * Is the given argument being completed? */ public boolean isArgument(int index) { return isArgument() && getIndex() == index; }
/** * If the command is being completed from anywhere at or after the given argument index, * generate suggestions for the entire command from that index, based on the given choices. */ public void suggestJoinedArguments(int start, Iterable<String> choices) throws SuggestException { final SuggestionContext ctx = getSuggestionContext(); if(ctx != null && ctx.isArgument()) { if(start == ctx.getIndex()) { ctx.suggestArgument(start, choices); } else if(start < ctx.getIndex()) { final String prefix = String.join(" ", parsedArgs.subList(start, ctx.getIndex())).toLowerCase() + " "; final List<String> filtered = new ArrayList<>(); for(String choice : choices) { if(choice.toLowerCase().startsWith(prefix)) { filtered.add(choice.substring(prefix.length())); } } ctx.suggestArgument(ctx.getIndex(), filtered); } } }
@Override public String toString() { return isArgument() ? "argument " + getIndex() : "flag -" + getFlag(); } }