JCommanderParameterResolver implements ParameterResolver { @Override public List<CompletionProposal> complete(MethodParameter parameter, CompletionContext context) { JCommander jCommander = createJCommander(parameter); List<String> words = context.getWords(); try { jCommander.parseWithoutValidation(words.toArray(new String[words.size()])); } catch (ParameterException ignored) { return Collections.emptyList(); } return streamAllJCommanderDescriptions(jCommander) .filter(p -> !p.isAssigned()) .flatMap(p -> Arrays.stream(p.getParameter().names())) .map(CompletionProposal::new) .collect(Collectors.toList()); }  @Autowired(required = false) void setValidatorFactory(ValidatorFactory validatorFactory); @Override boolean supports(MethodParameter parameter); @Override ValueResult resolve(MethodParameter methodParameter, List<String> words); @Override Stream<ParameterDescription> describe(MethodParameter parameter); @Override List<CompletionProposal> complete(MethodParameter parameter, CompletionContext context);  }
@Test public void testCanComplete() { MethodParameter methodParameter = Utils.createMethodParameter(COMMAND_METHOD, 0); CompletionContext context = new CompletionContext(Collections.emptyList(), 0, 0); Stream<String> proposals = resolver.complete(methodParameter, context).stream().map(CompletionProposal::value); assertThat(proposals).containsExactly("--name", "-n", "-level"); context = new CompletionContext(Arrays.asList("-n", "foo"), 0, 0); proposals = resolver.complete(methodParameter, context).stream().map(CompletionProposal::value); assertThat(proposals).containsExactly("-level"); }
@Test public void testCannotComplete() { MethodParameter methodParameter = Utils.createMethodParameter(COMMAND_METHOD, 0); CompletionContext context = new CompletionContext(Arrays.asList("--name"), 0, 0); Stream<String> proposals = resolver.complete(methodParameter, context).stream().map(CompletionProposal::value); assertThat(proposals).isEmpty(); }