Search in sources :

Example 6 with ConsoleReader

use of jline.console.ConsoleReader in project apex-core by apache.

the class ApexCliTest method testAppFromOnlyConfigPackage.

@Test
public void testAppFromOnlyConfigPackage() throws Exception {
    ApexCli.LaunchCommandLineInfo commandLineInfo = ApexCli.getLaunchCommandLineInfo(new String[] { "-conf", configFile.getAbsolutePath(), appFile.getAbsolutePath(), "-useConfigApps", "exclusive" });
    ApexCli apexCli = new ApexCli();
    apexCli.init();
    Assert.assertEquals("configApps", "exclusive", commandLineInfo.useConfigApps);
    apexCli.getLaunchAppPackageArgs(ap, cp, commandLineInfo, new ConsoleReader());
    Assert.assertEquals(ap.getApplications().size(), 1);
    Assert.assertEquals(ap.getApplications().get(0).displayName, "testApp");
    Assert.assertEquals(ap.getApplications().get(0).type, "json");
}
Also used : ConsoleReader(jline.console.ConsoleReader) Test(org.junit.Test)

Example 7 with ConsoleReader

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

the class Cat method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(paths.size() < 2, "Only one refspec allowed");
    checkParameter(!paths.isEmpty(), "A refspec must be specified");
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    String path = paths.get(0);
    Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(path).call();
    checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
    if (binary) {
        ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE;
        ObjectWriter<RevObject> writer = factory.createObjectWriter(obj.get().getType());
        writer.write(obj.get(), System.out);
    } else {
        CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(obj.get())).call();
        console.println(s);
    }
}
Also used : ObjectSerializingFactory(org.locationtech.geogig.storage.ObjectSerializingFactory) ConsoleReader(jline.console.ConsoleReader) RevObject(org.locationtech.geogig.api.RevObject) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 8 with ConsoleReader

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

the class ShowRef method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    ForEachRef op = geogig.command(ForEachRef.class);
    Predicate<Ref> filter = new Predicate<Ref>() {

        @Override
        public boolean apply(Ref ref) {
            String name = ref.getName();
            if (!name.startsWith(Ref.REFS_PREFIX)) {
                return false;
            }
            boolean match = patterns.isEmpty() ? true : false;
            for (String pattern : patterns) {
                if (Strings.isNullOrEmpty(pattern)) {
                    match = true;
                } else if (name.endsWith("/" + pattern)) {
                    match = true;
                    break;
                }
            }
            return match;
        }
    };
    op.setFilter(filter);
    ImmutableSet<Ref> refs = op.call();
    for (Ref ref : refs) {
        console.println(ref.getObjectId() + " " + ref.getName());
    }
}
Also used : Ref(org.locationtech.geogig.api.Ref) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) ConsoleReader(jline.console.ConsoleReader) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) GeoGIG(org.locationtech.geogig.api.GeoGIG) Predicate(com.google.common.base.Predicate)

Example 9 with ConsoleReader

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

the class Add method runInternal.

/**
     * Executes the add command using the provided options.
     * 
     * @param cli
     * @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    final GeoGIG geogig = cli.getGeogig();
    final ConsoleReader console = cli.getConsole();
    String pathFilter = null;
    if (patterns.size() == 1) {
        pathFilter = patterns.get(0);
    } else if (patterns.size() > 1) {
        throw new InvalidParameterException("Only a single path is supported so far");
    }
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    console.print("Counting unstaged elements...");
    console.flush();
    DiffObjectCount unstaged = geogig.getRepository().workingTree().countUnstaged(pathFilter);
    if (0 == unstaged.count() && conflicts.isEmpty()) {
        console.println();
        console.println("No unstaged elements, exiting.");
        return;
    } else {
        console.println(String.valueOf(unstaged.count()));
    }
    console.println("Staging changes...");
    AddOp op = geogig.command(AddOp.class);
    if (patterns.size() == 1) {
        op.addPattern(patterns.get(0));
    }
    WorkingTree workTree = op.setUpdateOnly(updateOnly).setProgressListener(cli.getProgressListener()).call();
    DiffObjectCount staged = geogig.getRepository().index().countStaged(null);
    unstaged = workTree.countUnstaged(null);
    console.println(staged.featureCount() + " features and " + staged.treeCount() + " trees staged for commit");
    console.println(unstaged.featureCount() + " features and " + unstaged.treeCount() + " trees not staged for commit");
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) WorkingTree(org.locationtech.geogig.repository.WorkingTree) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) ConsoleReader(jline.console.ConsoleReader) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 10 with ConsoleReader

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

the class MergeBase method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(commits.size() == 2, "Two commit references must be provided");
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0)).call();
    checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object.");
    checkParameter(left.get() instanceof RevCommit, commits.get(0) + " does not resolve to a commit");
    Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1)).call();
    checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object.");
    checkParameter(right.get() instanceof RevCommit, commits.get(1) + " does not resolve to a commit");
    Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class).setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call();
    checkParameter(ancestor.isPresent(), "No common ancestor was found.");
    console.print(ancestor.get().toString());
}
Also used : ConsoleReader(jline.console.ConsoleReader) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) FindCommonAncestor(org.locationtech.geogig.api.plumbing.FindCommonAncestor) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevCommit(org.locationtech.geogig.api.RevCommit)

Aggregations

ConsoleReader (jline.console.ConsoleReader)95 UnsupportedTerminal (jline.UnsupportedTerminal)44 GeogigCLI (org.locationtech.geogig.cli.GeogigCLI)42 GeoGIG (org.locationtech.geogig.api.GeoGIG)22 Before (org.junit.Before)19 IOException (java.io.IOException)17 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