Search in sources :

Example 81 with ConsoleReader

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

the class SQLServerDescribeTest method testDescribeException.

@Test
public void testDescribeException() throws Exception {
    ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    GeogigCLI mockCli = spy(new GeogigCLI(consoleReader));
    setUpGeogig(mockCli);
    when(mockCli.getConsole()).thenThrow(new MockitoException("Exception"));
    SQLServerDescribe describeCommand = new SQLServerDescribe();
    describeCommand.table = "table1";
    describeCommand.dataStoreFactory = TestHelper.createTestFactory();
    exception.expect(MockitoException.class);
    describeCommand.run(mockCli);
}
Also used : GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 82 with ConsoleReader

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

the class PGListTest method testListException.

@Test
public void testListException() throws Exception {
    ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    GeogigCLI mockCli = spy(new GeogigCLI(consoleReader));
    setUpGeogig(mockCli);
    when(mockCli.getConsole()).thenThrow(new MockitoException("Exception"));
    PGList listCommand = new PGList();
    listCommand.dataStoreFactory = TestHelper.createTestFactory();
    exception.expect(MockitoException.class);
    listCommand.run(mockCli);
}
Also used : GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 83 with ConsoleReader

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

the class Ls method runInternal.

@Override
public void runInternal(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();
    if (!iter.hasNext()) {
        if (ref == null) {
            console.println("The working tree is empty");
        } else {
            console.println("The specified path is empty");
        }
        return;
    }
    int depth = 0;
    if (ref == null) {
        console.println("Root tree/");
    } else {
        console.println(ref + "/");
        depth = ref.split("/").length - 1;
    }
    final int rootDepth = depth;
    Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {

        @Override
        public CharSequence apply(NodeRef input) {
            String path = input.path();
            int depth = path.split("/").length - rootDepth;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < depth; i++) {
                sb.append('\t');
            }
            sb.append(input.getNode().getName());
            if (input.getType().equals(TYPE.TREE)) {
                sb.append('/');
            }
            if (verbose) {
                sb.append(' ').append(abbrev(input.getMetadataId())).append(' ').append(abbrev(input.objectId()));
            }
            return sb.toString();
        }

        private String abbrev(ObjectId oid) {
            return abbrev == null ? oid.toString() : oid.toString().substring(0, abbrev.intValue());
        }
    };
    Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
    while (lines.hasNext()) {
        console.println(lines.next());
    }
    console.flush();
}
Also used : ConsoleReader(jline.console.ConsoleReader) ObjectId(org.locationtech.geogig.api.ObjectId) 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)

Example 84 with ConsoleReader

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

the class Tag method runInternal.

/**
     * Executes the commit command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter((message != null && !message.trim().isEmpty()) || nameAndCommit.isEmpty() || delete, "No tag message provided");
    checkParameter(nameAndCommit.size() < 2 || (nameAndCommit.size() == 2 && !delete), "Too many parameters provided");
    if (nameAndCommit.isEmpty()) {
        // looks like an attempt to create a tag with a message but forgot the tag name
        checkParameter(message == null, "A tag name must be provided");
        listTags(cli);
        return;
    }
    String name = nameAndCommit.get(0);
    String commit = nameAndCommit.size() > 1 ? nameAndCommit.get(1) : Ref.HEAD;
    ConsoleReader console = cli.getConsole();
    final GeoGIG geogig = cli.getGeogig();
    if (delete) {
        geogig.command(TagRemoveOp.class).setName(name).call();
        console.println("Deleted tag " + name);
    } else {
        Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit).call();
        checkParameter(commitId.isPresent(), "Wrong reference: " + commit);
        RevTag tag = geogig.command(TagCreateOp.class).setName(name).setMessage(message).setCommitId(commitId.get()).call();
        console.println("Created tag " + name + " -> " + tag.getCommitId());
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 85 with ConsoleReader

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

the class GlobalState method setupGeogig.

public static void setupGeogig() throws Exception {
    assertNotNull(platform);
    stdIn = new ByteArrayInputStream(new byte[0]);
    stdOut = new ByteArrayOutputStream();
    if (GlobalState.consoleReader != null) {
        GlobalState.consoleReader.shutdown();
    }
    // GlobalState.consoleReader = new ConsoleReader(stdIn,
    // new TeeOutputStream(stdOut, System.err), new UnsupportedTerminal());
    GlobalState.consoleReader = new ConsoleReader(stdIn, stdOut, new UnsupportedTerminal());
    ContextBuilder injectorBuilder = new CLITestContextBuilder(platform);
    Context injector = injectorBuilder.build();
    if (geogigCLI != null) {
        geogigCLI.close();
    }
    geogigCLI = new GeogigCLI(GlobalState.consoleReader);
    GlobalContextBuilder.builder = injectorBuilder;
    Platform platform = injector.platform();
    geogigCLI.setPlatform(platform);
    geogigCLI.tryConfigureLogging();
}
Also used : Context(org.locationtech.geogig.api.Context) GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ConsoleReader(jline.console.ConsoleReader) TestPlatform(org.locationtech.geogig.api.TestPlatform) Platform(org.locationtech.geogig.api.Platform) ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedTerminal(jline.UnsupportedTerminal) ContextBuilder(org.locationtech.geogig.api.ContextBuilder) GlobalContextBuilder(org.locationtech.geogig.api.GlobalContextBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

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