@Test public void testCompletionForSessionVariableNames() { final String topCommand = "session"; final String subCommand = "set"; final DefaultParser.ArgumentList parsedLine = new DefaultParser.ArgumentList( "", Arrays.asList(topCommand, subCommand), 2, -1, -1); final List<Candidate> candidates = new ArrayList<>(); completer.complete(lineReader, parsedLine, candidates); assertTrue(candidates.size() > 0); assertEquals(SessionVariable.values().length, candidates.size()); }
@Override public void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates) { Objects.requireNonNull(line); Objects.requireNonNull(candidates); if (line.wordIndex() < 0) { return; } if (line.wordIndex() == 0) { addCandidates(topLevelCommandMap.keySet(), candidates); return; } if (line.wordIndex() == 1) { final String firstLevel = line.words().get(0); if (topLevelCommandMap.containsKey(firstLevel)) { final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (subCommands != null) { addCandidates(subCommands, candidates); } } return; } if (line.wordIndex() >= 2) { final String firstLevel = line.words().get(0); final String secondLevel = line.words().get(1); if (!topLevelCommandMap.containsKey(firstLevel)) { return; } final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (!subCommands.contains(secondLevel)) { return; } if (!commandOptionsMap.containsKey(secondLevel)) { return; } if (SessionCommandGroup.NAME.equals(firstLevel)) { if (line.wordIndex() == 2) { addCandidates(SessionVariable.getAllVariableNames(), candidates); } else if (line.wordIndex() == 3) { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_VARS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } } } else { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_ARGS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } else { final List<String> options = commandOptionsMap.get(secondLevel); if (options != null) { addCandidates(options, candidates); } } } } }
CLICompleter implements Completer { @Override public void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates) { Objects.requireNonNull(line); Objects.requireNonNull(candidates); if (line.wordIndex() < 0) { return; } if (line.wordIndex() == 0) { addCandidates(topLevelCommandMap.keySet(), candidates); return; } if (line.wordIndex() == 1) { final String firstLevel = line.words().get(0); if (topLevelCommandMap.containsKey(firstLevel)) { final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (subCommands != null) { addCandidates(subCommands, candidates); } } return; } if (line.wordIndex() >= 2) { final String firstLevel = line.words().get(0); final String secondLevel = line.words().get(1); if (!topLevelCommandMap.containsKey(firstLevel)) { return; } final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (!subCommands.contains(secondLevel)) { return; } if (!commandOptionsMap.containsKey(secondLevel)) { return; } if (SessionCommandGroup.NAME.equals(firstLevel)) { if (line.wordIndex() == 2) { addCandidates(SessionVariable.getAllVariableNames(), candidates); } else if (line.wordIndex() == 3) { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_VARS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } } } else { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_ARGS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } else { final List<String> options = commandOptionsMap.get(secondLevel); if (options != null) { addCandidates(options, candidates); } } } } } }
CLICompleter implements Completer { @Override public void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates) { Objects.requireNonNull(line); Objects.requireNonNull(candidates); if (line.wordIndex() < 0) { return; } if (line.wordIndex() == 0) { addCandidates(topLevelCommandMap.keySet(), candidates); return; } if (line.wordIndex() == 1) { final String firstLevel = line.words().get(0); if (topLevelCommandMap.containsKey(firstLevel)) { final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (subCommands != null) { addCandidates(subCommands, candidates); } } return; } if (line.wordIndex() >= 2) { final String firstLevel = line.words().get(0); final String secondLevel = line.words().get(1); if (!topLevelCommandMap.containsKey(firstLevel)) { return; } final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (!subCommands.contains(secondLevel)) { return; } if (!commandOptionsMap.containsKey(secondLevel)) { return; } if (SessionCommandGroup.NAME.equals(firstLevel)) { if (line.wordIndex() == 2) { addCandidates(SessionVariable.getAllVariableNames(), candidates); } else if (line.wordIndex() == 3) { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_VARS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } } } else { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_ARGS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } else { final List<String> options = commandOptionsMap.get(secondLevel); if (options != null) { addCandidates(options, candidates); } } } } } CLICompleter(final Collection<Command> topLevelCommands, final Collection<CommandGroup> commandGroups); }
CLICompleter implements Completer { @Override public void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates) { Objects.requireNonNull(line); Objects.requireNonNull(candidates); if (line.wordIndex() < 0) { return; } if (line.wordIndex() == 0) { addCandidates(topLevelCommandMap.keySet(), candidates); return; } if (line.wordIndex() == 1) { final String firstLevel = line.words().get(0); if (topLevelCommandMap.containsKey(firstLevel)) { final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (subCommands != null) { addCandidates(subCommands, candidates); } } return; } if (line.wordIndex() >= 2) { final String firstLevel = line.words().get(0); final String secondLevel = line.words().get(1); if (!topLevelCommandMap.containsKey(firstLevel)) { return; } final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (!subCommands.contains(secondLevel)) { return; } if (!commandOptionsMap.containsKey(secondLevel)) { return; } if (SessionCommandGroup.NAME.equals(firstLevel)) { if (line.wordIndex() == 2) { addCandidates(SessionVariable.getAllVariableNames(), candidates); } else if (line.wordIndex() == 3) { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_VARS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } } } else { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_ARGS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } else { final List<String> options = commandOptionsMap.get(secondLevel); if (options != null) { addCandidates(options, candidates); } } } } } CLICompleter(final Collection<Command> topLevelCommands, final Collection<CommandGroup> commandGroups); Collection<String> getTopLevelCommands(); Collection<String> getSubCommands(final String topLevelCommand); Collection<String> getOptions(final String secondLevelCommand); @Override void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates); }
CLICompleter implements Completer { @Override public void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates) { Objects.requireNonNull(line); Objects.requireNonNull(candidates); if (line.wordIndex() < 0) { return; } if (line.wordIndex() == 0) { addCandidates(topLevelCommandMap.keySet(), candidates); return; } if (line.wordIndex() == 1) { final String firstLevel = line.words().get(0); if (topLevelCommandMap.containsKey(firstLevel)) { final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (subCommands != null) { addCandidates(subCommands, candidates); } } return; } if (line.wordIndex() >= 2) { final String firstLevel = line.words().get(0); final String secondLevel = line.words().get(1); if (!topLevelCommandMap.containsKey(firstLevel)) { return; } final List<String> subCommands = topLevelCommandMap.get(firstLevel); if (!subCommands.contains(secondLevel)) { return; } if (!commandOptionsMap.containsKey(secondLevel)) { return; } if (SessionCommandGroup.NAME.equals(firstLevel)) { if (line.wordIndex() == 2) { addCandidates(SessionVariable.getAllVariableNames(), candidates); } else if (line.wordIndex() == 3) { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_VARS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } } } else { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_ARGS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); fileNameCompleter.complete(reader, new ArgumentCompleter.ArgumentLine(currWord, currWord.length()), candidates); } else { final List<String> options = commandOptionsMap.get(secondLevel); if (options != null) { addCandidates(options, candidates); } } } } } CLICompleter(final Collection<Command> topLevelCommands, final Collection<CommandGroup> commandGroups); Collection<String> getTopLevelCommands(); Collection<String> getSubCommands(final String topLevelCommand); Collection<String> getOptions(final String secondLevelCommand); @Override void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates);  }