Search in sources :

Example 1 with Candidate

use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.

the class FeatureCompleterSupport method complete.

@Override
public int complete(Session session, final CommandLine commandLine, final List<String> candidates) {
    List<Candidate> cands = new ArrayList<>();
    completeCandidates(session, commandLine, cands);
    for (Candidate cand : cands) {
        candidates.add(cand.value());
    }
    return candidates.isEmpty() ? -1 : 0;
}
Also used : Candidate(org.apache.karaf.shell.api.console.Candidate) ArrayList(java.util.ArrayList)

Example 2 with Candidate

use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.

the class AggregateCompleter method complete.

@SuppressWarnings({ "unchecked", "rawtypes" })
public int complete(final Session session, final CommandLine commandLine, final List<String> candidates) {
    List<Candidate> cands = new ArrayList<>();
    completeCandidates(session, commandLine, cands);
    for (Candidate cand : cands) {
        candidates.add(cand.value());
    }
    return 0;
}
Also used : Candidate(org.apache.karaf.shell.api.console.Candidate) ArrayList(java.util.ArrayList)

Example 3 with Candidate

use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.

the class UriCompleter method maven.

private void maven(Session session, CommandLine commandLine, List<Candidate> candidates) {
    String repo = System.getProperty("user.home") + "/.m2/repository";
    String buffer = commandLine.getCursorArgument();
    String mvn = buffer.substring("mvn:".length(), commandLine.getArgumentPosition());
    String rem = "";
    try {
        String[] parts = mvn.split("/");
        if (parts.length == 0 || parts.length == 1 && !mvn.endsWith("/")) {
            String known = "";
            String group = "";
            String[] dirs = parts.length > 0 ? parts[0].split("\\.") : new String[] { "" };
            if (parts.length > 0 && parts[0].endsWith(".")) {
                for (String dir : dirs) {
                    known += dir + "/";
                    group += dir + ".";
                }
            } else {
                for (int i = 0; i < dirs.length - 1; i++) {
                    known += dirs[i] + "/";
                    group += dirs[i] + ".";
                }
                rem = dirs[dirs.length - 1];
            }
            Path rep = Paths.get(repo);
            Path dir = rep.resolve(known);
            try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
                for (Path path : paths) {
                    if (Files.isDirectory(path)) {
                        String name = path.getFileName().toString();
                        candidates.add(new Candidate("mvn:" + group + name, false));
                    }
                }
            }
            rem = group + rem;
        } else if (parts.length == 1 || parts.length == 2 && !mvn.endsWith("/")) {
            rem = parts.length > 1 ? parts[1] : "";
            Path dir = Paths.get(repo + "/" + parts[0].replace(".", "/"));
            try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
                for (Path path : paths) {
                    if (Files.isDirectory(path)) {
                        String name = path.getFileName().toString();
                        candidates.add(new Candidate("mvn:" + parts[0] + "/" + name, false));
                    }
                }
            }
        } else if (parts.length == 2 || parts.length == 3 && !mvn.endsWith("/")) {
            rem = parts.length > 2 ? parts[2] : "";
            Path dir = Paths.get(repo + "/" + parts[0].replace(".", "/") + "/" + parts[1]);
            try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
                for (Path path : paths) {
                    if (Files.isDirectory(path)) {
                        String name = path.getFileName().toString();
                        candidates.add(new Candidate("mvn:" + parts[0] + "/" + parts[1] + "/" + name, true));
                    }
                }
            }
        }
    } catch (Exception e) {
    // Ignore
    }
}
Also used : Path(java.nio.file.Path) Candidate(org.apache.karaf.shell.api.console.Candidate) DirectoryStream(java.nio.file.DirectoryStream)

Example 4 with Candidate

use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.

the class ArgumentCompleter method complete.

public int complete(Session session, final CommandLine commandLine, final List<String> candidates) {
    List<Candidate> cands = new ArrayList<>();
    completeCandidates(session, commandLine, cands);
    for (Candidate cand : cands) {
        candidates.add(cand.value());
    }
    return 0;
}
Also used : Candidate(org.apache.karaf.shell.api.console.Candidate) ArrayList(java.util.ArrayList)

Example 5 with Candidate

use of org.apache.karaf.shell.api.console.Candidate in project karaf by apache.

the class CommandsCompleter method complete.

public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    List<Candidate> cands = new ArrayList<>();
    completeCandidates(session, commandLine, cands);
    for (Candidate cand : cands) {
        candidates.add(cand.value());
    }
    return 0;
}
Also used : Candidate(org.apache.karaf.shell.api.console.Candidate) ArrayList(java.util.ArrayList)

Aggregations

Candidate (org.apache.karaf.shell.api.console.Candidate)9 ArrayList (java.util.ArrayList)6 Path (java.nio.file.Path)3 ArgumentCommandLine (org.apache.karaf.shell.support.completers.ArgumentCommandLine)2 IOException (java.io.IOException)1 DirectoryStream (java.nio.file.DirectoryStream)1 CommandLine (org.apache.karaf.shell.api.console.CommandLine)1 Terminal (org.jline.terminal.Terminal)1