Search in sources :

Example 56 with ConsoleReader

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

the class LsTree method runInternal.

@Override
public void runInternal(final GeogigCLI cli) throws IOException {
    String ref;
    if (refList.isEmpty()) {
        ref = null;
    } else {
        ref = refList.get(0);
    }
    Strategy lsStrategy = Strategy.CHILDREN;
    if (recursive) {
        if (includeTrees) {
            lsStrategy = Strategy.DEPTHFIRST;
        } else if (onlyTrees) {
            lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
        } else {
            lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
        }
    } else {
        if (onlyTrees) {
            lsStrategy = Strategy.TREES_ONLY;
        }
    }
    Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
    final ConsoleReader console = cli.getConsole();
    Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {

        @Override
        public CharSequence apply(NodeRef input) {
            StringBuilder sb = new StringBuilder();
            if (!verbose) {
                sb.append(input.path());
            } else {
                Envelope env = new Envelope();
                input.getNode().expand(env);
                StringBuilder sbenv = new StringBuilder();
                sbenv.append(Double.toString(env.getMinX())).append(";").append(Double.toString(env.getMaxX())).append(";").append(Double.toString(env.getMinY())).append(";").append(Double.toString(env.getMaxY()));
                sb.append(input.getMetadataId().toString()).append(' ').append(input.getType().toString().toLowerCase()).append(' ').append(input.objectId().toString()).append(' ').append(input.path()).append(' ').append(sbenv);
                if (input.getType().equals(TYPE.TREE)) {
                    RevTree tree = cli.getGeogig().command(RevObjectParse.class).setObjectId(input.objectId()).call(RevTree.class).get();
                    sb.append(' ').append(tree.size()).append(' ').append(tree.numTrees());
                }
            }
            return sb;
        }
    };
    Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
    while (lines.hasNext()) {
        console.println(lines.next());
    }
    console.flush();
}
Also used : ConsoleReader(jline.console.ConsoleReader) Envelope(com.vividsolutions.jts.geom.Envelope) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) Strategy(org.locationtech.geogig.api.plumbing.LsTreeOp.Strategy) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevTree(org.locationtech.geogig.api.RevTree)

Example 57 with ConsoleReader

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

the class GeogigConsole method run.

private void run(final InputStream in, final OutputStream out) throws IOException {
    final Terminal terminal;
    if (interactive) {
        terminal = null;
    /* let jline select an appropriate one */
    } else {
        // no colors in output
        terminal = new UnsupportedTerminal();
    }
    ConsoleReader consoleReader = new ConsoleReader(in, out, terminal);
    consoleReader.setAutoprintThreshold(20);
    consoleReader.setPaginationEnabled(interactive);
    consoleReader.setHistoryEnabled(interactive);
    // needed for CTRL+C not to let the console broken
    consoleReader.getTerminal().setEchoEnabled(interactive);
    final GeogigCLI cli = new GeogigCLI(consoleReader);
    if (interactive) {
        addCommandCompleter(consoleReader, cli);
    } else {
        // no progress percent in output
        cli.disableProgressListener();
    }
    GeogigCLI.addShutdownHook(cli);
    setPrompt(cli);
    cli.close();
    try {
        runInternal(cli);
    } finally {
        try {
            cli.close();
        } finally {
            try {
                if (terminal != null) {
                    terminal.restore();
                }
                consoleReader.shutdown();
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) Terminal(jline.Terminal) UnsupportedTerminal(jline.UnsupportedTerminal) IOException(java.io.IOException)

Example 58 with ConsoleReader

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

the class GeogigConsole method runInternal.

private void runInternal(final GeogigCLI cli) throws IOException {
    final ConsoleReader consoleReader = cli.getConsole();
    while (true) {
        String line = consoleReader.readLine();
        if (line == null) {
            // EOF / CTRL-D
            return;
        }
        if (line.trim().length() == 0) {
            continue;
        }
        if (line.trim().startsWith("#")) {
            // comment
            continue;
        }
        String[] args = ArgumentTokenizer.tokenize(line);
        if (interactive && args != null && args.length == 1) {
            if ("exit".equals(args[0])) {
                return;
            }
            if ("clear".equals(args[0])) {
                consoleReader.clearScreen();
                consoleReader.redrawLine();
                continue;
            }
        }
        cli.execute(args);
        // in case HEAD has changed
        setPrompt(cli);
        cli.close();
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader)

Example 59 with ConsoleReader

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

the class VerifyPatch method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(patchFiles.size() < 2, "Only one single patch file accepted");
    checkParameter(!patchFiles.isEmpty(), "No patch file specified");
    ConsoleReader console = cli.getConsole();
    File patchFile = new File(patchFiles.get(0));
    checkParameter(patchFile.exists(), "Patch file cannot be found");
    FileInputStream stream;
    try {
        stream = new FileInputStream(patchFile);
    } catch (FileNotFoundException e1) {
        throw new IllegalStateException("Can't open patch file " + patchFile);
    }
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        Closeables.closeQuietly(reader);
        Closeables.closeQuietly(stream);
        throw new IllegalStateException("Error reading patch file " + patchFile, e);
    }
    Patch patch = PatchSerializer.read(reader);
    Closeables.closeQuietly(reader);
    Closeables.closeQuietly(stream);
    VerifyPatchResults verify = cli.getGeogig().command(VerifyPatchOp.class).setPatch(patch).setReverse(reverse).call();
    Patch toReject = verify.getToReject();
    Patch toApply = verify.getToApply();
    if (toReject.isEmpty()) {
        console.println("Patch can be applied.");
    } else {
        console.println("Error: Patch cannot be applied\n");
        console.println("Applicable entries:\n");
        console.println(toApply.toString());
        console.println("\nConflicting entries:\n");
        console.println(toReject.toString());
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VerifyPatchResults(org.locationtech.geogig.api.plumbing.diff.VerifyPatchResults) File(java.io.File) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) VerifyPatchOp(org.locationtech.geogig.api.plumbing.diff.VerifyPatchOp) FileInputStream(java.io.FileInputStream)

Example 60 with ConsoleReader

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

the class WalkGraph method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    String ref;
    if (refList.isEmpty()) {
        ref = null;
    } else {
        ref = refList.get(0);
    }
    Deduplicator deduplicator = cli.getGeogig().command(CreateDeduplicator.class).call();
    try {
        Iterator<RevObject> iter = //
        cli.getGeogig().command(WalkGraphOp.class).setReference(//
        ref).setDeduplicator(//
        deduplicator).call();
        final ConsoleReader console = cli.getConsole();
        if (!iter.hasNext()) {
            if (ref == null) {
                console.println("The working tree is empty");
            } else {
                console.println("The specified path is empty");
            }
            return;
        }
        Function<RevObject, CharSequence> printFunctor = new Function<RevObject, CharSequence>() {

            @Override
            public CharSequence apply(RevObject input) {
                if (verbose) {
                    return String.format("%s: %s %s", input.getId(), input.getType(), input);
                } else {
                    return String.format("%s: %s", input.getId(), input.getType());
                }
            }
        };
        Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
        while (lines.hasNext()) {
            console.println(lines.next());
        }
        console.flush();
    } finally {
        deduplicator.release();
    }
}
Also used : WalkGraphOp(org.locationtech.geogig.api.plumbing.WalkGraphOp) Function(com.google.common.base.Function) ConsoleReader(jline.console.ConsoleReader) RevObject(org.locationtech.geogig.api.RevObject) CreateDeduplicator(org.locationtech.geogig.api.plumbing.CreateDeduplicator) Deduplicator(org.locationtech.geogig.storage.Deduplicator) CreateDeduplicator(org.locationtech.geogig.api.plumbing.CreateDeduplicator)

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