/** * Is the given argument being completed? */ public boolean isArgument(int index) { return isArgument() && getIndex() == index; }
/** * If the given argument is being completed, generate suggestions from the given choices, * by throwing a {@link SuggestException}. */ public void suggestArgument(int index, Iterable<String> choices) throws SuggestException { if(isArgument(index)) { suggest(choices); } }
/** * Is the given argument being completed? */ public boolean isSuggestingArgument(int index) { return isSuggesting() && getSuggestionContext().isArgument(index); }
@Override public String toString() { return isArgument() ? "argument " + getIndex() : "flag -" + getFlag(); } }
/** * 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); } } }
/** * If the given argument is being completed, generate suggestions based on the given choices. */ public void suggestArgument(int index, Iterable<String> choices) throws SuggestException { if(isSuggesting() && getSuggestionContext().isArgument()) { getSuggestionContext().suggestArgument(index, choices); } }