Search in sources :

Example 61 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class Diff method runInternal.

/**
     * Executes the diff command with the specified options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(refSpec.size() <= 2, "Commit list is too long :%s", refSpec);
    checkParameter(!(nogeom && summary), "Only one printing mode allowed");
    checkParameter(!(bounds && count), "Only one of --bounds or --count is allowed");
    checkParameter(!(cached && refSpec.size() > 1), "--cached allows zero or one ref specs to compare the index with.");
    GeoGIG geogig = cli.getGeogig();
    String oldVersion = resolveOldVersion();
    String newVersion = resolveNewVersion();
    List<String> paths = removeEmptyPaths();
    if (bounds) {
        DiffBounds diff = geogig.command(DiffBounds.class).setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
        diff.setPathFilters(paths);
        CoordinateReferenceSystem crs = parseCrs();
        if (crs != null) {
            diff.setCRS(crs);
        }
        DiffSummary<BoundingBox, BoundingBox> diffBounds = diff.call();
        BoundsDiffPrinter.print(geogig, cli.getConsole(), diffBounds);
        return;
    }
    if (count) {
        if (oldVersion == null) {
            oldVersion = Ref.HEAD;
        }
        if (newVersion == null) {
            newVersion = cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD;
        }
        DiffCount cdiff = geogig.command(DiffCount.class).setOldVersion(oldVersion).setNewVersion(newVersion);
        cdiff.setFilter(paths);
        DiffObjectCount count = cdiff.call();
        ConsoleReader console = cli.getConsole();
        console.println(String.format("Trees changed: %d, features changed: %,d", count.treeCount(), count.featureCount()));
        console.flush();
        return;
    }
    DiffOp diff = geogig.command(DiffOp.class);
    diff.setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
    Iterator<DiffEntry> entries;
    if (paths.isEmpty()) {
        entries = diff.setProgressListener(cli.getProgressListener()).call();
    } else {
        entries = Iterators.emptyIterator();
        for (String path : paths) {
            Iterator<DiffEntry> moreEntries = diff.setFilter(path).setProgressListener(cli.getProgressListener()).call();
            entries = Iterators.concat(entries, moreEntries);
        }
    }
    if (!entries.hasNext()) {
        cli.getConsole().println("No differences found");
        return;
    }
    DiffPrinter printer;
    if (summary) {
        printer = new SummaryDiffPrinter();
    } else {
        printer = new FullDiffPrinter(nogeom, false);
    }
    DiffEntry entry;
    while (entries.hasNext()) {
        entry = entries.next();
        printer.print(geogig, cli.getConsole(), entry);
    }
}
Also used : DiffBounds(org.locationtech.geogig.api.plumbing.DiffBounds) ConsoleReader(jline.console.ConsoleReader) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DiffCount(org.locationtech.geogig.api.plumbing.DiffCount) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 62 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class RebuildGraph method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    ImmutableList<ObjectId> updatedObjects = cli.getGeogig().command(RebuildGraphOp.class).call();
    final ConsoleReader console = cli.getConsole();
    if (updatedObjects.size() > 0) {
        if (quiet) {
            console.println(updatedObjects.size() + " graph elements (commits) were fixed.");
        } else {
            console.println("The following graph elements (commits) were incomplete or missing and have been fixed:");
            for (ObjectId object : updatedObjects) {
                console.println(object.toString());
            }
        }
    } else {
        console.println("No missing or incomplete graph elements (commits) were found.");
    }
}
Also used : RebuildGraphOp(org.locationtech.geogig.api.plumbing.RebuildGraphOp) ConsoleReader(jline.console.ConsoleReader) ObjectId(org.locationtech.geogig.api.ObjectId)

Example 63 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class RevParse method runInternal.

/**
     * Executes the rev-parse command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    GeoGIG geogig = cli.getGeogig();
    if (!refSpecs.isEmpty()) {
        checkParameter(!(resolve_geogig_dir || is_inside_work_tree), "if refSpec is given, --resolve-geogig-dir or --is-inside-work-tree shall not be specified");
        ConsoleReader console = cli.getConsole();
        for (String refSpec : this.refSpecs) {
            Optional<ObjectId> resolved = geogig.command(org.locationtech.geogig.api.plumbing.RevParse.class).setRefSpec(refSpec).call();
            checkParameter(resolved.isPresent(), "fatal: ambiguous argument '%s': " + "unknown revision or path not in the working tree.", refSpec);
            console.println(resolved.get().toString());
        }
        console.flush();
        return;
    }
    boolean closeIt = false;
    if (null == geogig) {
        geogig = cli.newGeoGIG(Hints.readOnly());
        closeIt = true;
    }
    try {
        if (resolve_geogig_dir) {
            resolveGeogigDir(cli.getConsole(), geogig);
        } else if (is_inside_work_tree) {
            isInsideWorkTree(cli.getConsole(), geogig);
        }
    } finally {
        if (closeIt) {
            geogig.close();
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) ObjectId(org.locationtech.geogig.api.ObjectId) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 64 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class GeogigCLI method printShortCommandList.

/**
     * This prints out only porcelain commands
     * 
     * @param mainCommander
     * 
     * @throws IOException
     */
public void printShortCommandList(JCommander mainCommander) {
    TreeSet<String> commandNames = Sets.newTreeSet();
    int longestCommandLenght = 0;
    // do this to ignore aliases
    for (String name : mainCommander.getCommands().keySet()) {
        JCommander command = mainCommander.getCommands().get(name);
        Class<? extends Object> clazz = command.getObjects().get(0).getClass();
        String packageName = clazz.getPackage().getName();
        if (!packageName.startsWith("org.locationtech.geogig.cli.plumbing")) {
            commandNames.add(name);
            longestCommandLenght = Math.max(longestCommandLenght, name.length());
        }
    }
    ConsoleReader console = getConsole();
    try {
        console.println("usage: geogig <command> [<args>]");
        console.println();
        console.println("The most commonly used geogig commands are:");
        for (String cmd : commandNames) {
            console.print(Strings.padEnd(cmd, longestCommandLenght, ' '));
            console.print("\t");
            console.println(mainCommander.getCommandDescription(cmd));
        }
        console.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) JCommander(com.beust.jcommander.JCommander) IOException(java.io.IOException)

Example 65 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class GeogigCLI method printCommandList.

/**
     * This prints out all commands, including plumbing ones, without description
     * 
     * @param mainCommander
     * @throws IOException
     */
public void printCommandList(JCommander mainCommander) {
    TreeSet<String> commandNames = Sets.newTreeSet();
    int longestCommandLenght = 0;
    // do this to ignore aliases
    for (String name : mainCommander.getCommands().keySet()) {
        commandNames.add(name);
        longestCommandLenght = Math.max(longestCommandLenght, name.length());
    }
    ConsoleReader console = getConsole();
    try {
        console.println("usage: geogig <command> [<args>]");
        console.println();
        int i = 0;
        for (String cmd : commandNames) {
            console.print(Strings.padEnd(cmd, longestCommandLenght, ' '));
            i++;
            if (i % 3 == 0) {
                console.println();
            } else {
                console.print("\t");
            }
        }
        console.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException)

Aggregations

ConsoleReader (jline.console.ConsoleReader)97 UnsupportedTerminal (jline.UnsupportedTerminal)44 GeogigCLI (org.locationtech.geogig.cli.GeogigCLI)42 GeoGIG (org.locationtech.geogig.api.GeoGIG)22 IOException (java.io.IOException)19 Before (org.junit.Before)19 Test (org.junit.Test)17 File (java.io.File)12 MockitoException (org.mockito.exceptions.base.MockitoException)12 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)11 ObjectId (org.locationtech.geogig.api.ObjectId)9 TestPlatform (org.locationtech.geogig.api.TestPlatform)8 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)8 Ref (org.locationtech.geogig.api.Ref)7 CLITestContextBuilder (org.locationtech.geogig.cli.test.functional.general.CLITestContextBuilder)7 Ansi (org.fusesource.jansi.Ansi)6 NodeRef (org.locationtech.geogig.api.NodeRef)6 RevCommit (org.locationtech.geogig.api.RevCommit)6 FileInputStream (java.io.FileInputStream)4 RevObject (org.locationtech.geogig.api.RevObject)4