Search in sources :

Example 31 with ConsoleReader

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

the class Fetch method runInternal.

/**
     * Executes the fetch command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(depth > 0 ? !fulldepth : true, "Cannot specify a depth and full depth.  Use --depth <depth> or --fulldepth.");
    if (depth > 0 || fulldepth) {
        checkParameter(cli.getGeogig().getRepository().getDepth().isPresent(), "Depth operations can only be used on a shallow clone.");
    }
    TransferSummary result;
    try {
        FetchOp fetch = cli.getGeogig().command(FetchOp.class);
        fetch.setProgressListener(cli.getProgressListener());
        fetch.setAll(all).setPrune(prune).setFullDepth(fulldepth);
        fetch.setDepth(depth);
        if (args != null) {
            for (String repo : args) {
                fetch.addRemote(repo);
            }
        }
        result = fetch.call();
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                throw new CommandFailedException("Unable to fetch, the remote history is shallow.", e);
        }
    } catch (IllegalArgumentException iae) {
        throw new CommandFailedException(iae.getMessage(), iae);
    } catch (IllegalStateException ise) {
        throw new CommandFailedException(ise.getMessage(), ise);
    }
    ConsoleReader console = cli.getConsole();
    if (result.getChangedRefs().isEmpty()) {
        console.println("Already up to date.");
    } else {
        FetchResultPrinter.print(result, console);
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) FetchOp(org.locationtech.geogig.api.porcelain.FetchOp) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Example 32 with ConsoleReader

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

the class OSMMapTest method setUp.

@Before
public void setUp() throws Exception {
    ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    cli = new GeogigCLI(consoleReader);
    File workingDirectory = tempFolder.getRoot();
    TestPlatform platform = new TestPlatform(workingDirectory);
    GlobalContextBuilder.builder = new CLITestContextBuilder(platform);
    cli.setPlatform(platform);
    cli.execute("init");
    cli.execute("config", "user.name", "Gabriel Roldan");
    cli.execute("config", "user.email", "groldan@boundlessgeo.com");
    assertTrue(new File(workingDirectory, ".geogig").exists());
}
Also used : GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) TestPlatform(org.locationtech.geogig.api.TestPlatform) File(java.io.File) CLITestContextBuilder(org.locationtech.geogig.cli.test.functional.general.CLITestContextBuilder) Before(org.junit.Before)

Example 33 with ConsoleReader

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

the class OSMUnmapTest method setUp.

@Before
public void setUp() throws Exception {
    ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    cli = new GeogigCLI(consoleReader);
    File workingDirectory = tempFolder.getRoot();
    TestPlatform platform = new TestPlatform(workingDirectory);
    GlobalContextBuilder.builder = new CLITestContextBuilder(platform);
    cli.setPlatform(platform);
    cli.execute("init");
    cli.execute("config", "user.name", "Gabriel Roldan");
    cli.execute("config", "user.email", "groldan@boundlessgeo.com");
    assertTrue(new File(workingDirectory, ".geogig").exists());
    // import with mapping
    String filename = OSMImportOp.class.getResource("nodes.xml").getFile();
    File file = new File(filename);
    String mappingFilename = OSMMap.class.getResource("nodes_mapping_with_aliases.json").getFile();
    File mappingFile = new File(mappingFilename);
    cli.execute("osm", "import", file.getAbsolutePath(), "--mapping", mappingFile.getAbsolutePath());
    GeoGIG geogig = cli.newGeoGIG();
    Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:busstops/507464799").call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    geogig.getRepository().workingTree().delete("node");
    Optional<RevTree> tree = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node").call(RevTree.class);
    assertFalse(tree.isPresent());
    geogig.close();
}
Also used : ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) OSMImportOp(org.locationtech.geogig.osm.internal.OSMImportOp) GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) RevFeature(org.locationtech.geogig.api.RevFeature) TestPlatform(org.locationtech.geogig.api.TestPlatform) File(java.io.File) CLITestContextBuilder(org.locationtech.geogig.cli.test.functional.general.CLITestContextBuilder) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree) Before(org.junit.Before)

Example 34 with ConsoleReader

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

the class ConsoleResourceResource method processRequest.

private JsonObject processRequest(JsonObject json, final GeoGIG geogig) {
    JsonObject response;
    final String command = json.get("method").getAsString();
    final String queryId = json.get("id").getAsString();
    // not used, we're getting the whole command and args in the "method" object
    // JsonArray paramsArray = json.get("params").getAsJsonArray();
    InputStream in = new ByteArrayInputStream(new byte[0]);
    // dumps output to a temp file if > threshold
    FileBackedOutputStream out = new FileBackedOutputStream(4096);
    try {
        // pass it a BufferedOutputStream 'cause it doesn't buffer the internal FileOutputStream
        ConsoleReader console = new ConsoleReader(in, new BufferedOutputStream(out), new UnsupportedTerminal());
        Platform platform = geogig.getPlatform();
        GeogigCLI geogigCLI = new GeogigCLI(geogig, console);
        geogigCLI.setPlatform(platform);
        geogigCLI.disableProgressListener();
        String[] args = ArgumentTokenizer.tokenize(command);
        final int exitCode = geogigCLI.execute(args);
        response = new JsonObject();
        response.addProperty("id", queryId);
        final int charCountLimit = getOutputLimit(geogig.getContext());
        final StringBuilder output = getLimitedOutput(out, charCountLimit);
        if (exitCode == 0) {
            response.addProperty("result", output.toString());
            response.addProperty("error", (String) null);
        } else {
            Exception exception = geogigCLI.exception;
            JsonObject error = buildError(exitCode, output, exception);
            response.add("error", error);
        }
        return response;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } finally {
        // delete temp file
        try {
            out.reset();
        } catch (IOException ignore) {
            ignore.printStackTrace();
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) Platform(org.locationtech.geogig.api.Platform) UnsupportedTerminal(jline.UnsupportedTerminal) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) IOException(java.io.IOException) GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ByteArrayInputStream(java.io.ByteArrayInputStream) FileBackedOutputStream(com.google.common.io.FileBackedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 35 with ConsoleReader

use of jline.console.ConsoleReader in project hive by apache.

the class BeeLine method connectUsingArgs.

/*
   * Connects using the command line arguments. There are two
   * possible ways to connect here 1. using the cmd line arguments like -u
   * or using !properties <property-file>
   */
private boolean connectUsingArgs(BeelineParser beelineParser, CommandLine cl) {
    String driver = null, user = null, pass = "", url = null;
    String auth = null;
    if (cl.hasOption("help")) {
        usage();
        getOpts().setHelpAsked(true);
        return true;
    }
    Properties hiveVars = cl.getOptionProperties("hivevar");
    for (String key : hiveVars.stringPropertyNames()) {
        getOpts().getHiveVariables().put(key, hiveVars.getProperty(key));
    }
    Properties hiveConfs = cl.getOptionProperties("hiveconf");
    for (String key : hiveConfs.stringPropertyNames()) {
        setHiveConfVar(key, hiveConfs.getProperty(key));
    }
    driver = cl.getOptionValue("d");
    auth = cl.getOptionValue("a");
    user = cl.getOptionValue("n");
    getOpts().setAuthType(auth);
    if (cl.hasOption("w")) {
        pass = obtainPasswordFromFile(cl.getOptionValue("w"));
    } else {
        if (beelineParser.isPasswordOptionSet) {
            pass = cl.getOptionValue("p");
        }
    }
    url = cl.getOptionValue("u");
    if ((url == null) && cl.hasOption("reconnect")) {
        // If url was not specified with -u, but -r was present, use that.
        url = getOpts().getLastConnectedUrl();
    }
    getOpts().setInitFiles(cl.getOptionValues("i"));
    getOpts().setScriptFile(cl.getOptionValue("f"));
    if (url != null) {
        // make sure we don't override the values present in the url with empty values.
        if (user == null) {
            user = Utils.parsePropertyFromUrl(url, JdbcConnectionParams.AUTH_USER);
        }
        if (pass == null) {
            pass = Utils.parsePropertyFromUrl(url, JdbcConnectionParams.AUTH_PASSWD);
        }
        if (driver == null) {
            driver = Utils.parsePropertyFromUrl(url, JdbcConnectionParams.PROPERTY_DRIVER);
        }
        String com;
        String comForDebug;
        if (pass != null) {
            com = constructCmd(url, user, pass, driver, false);
            comForDebug = constructCmd(url, user, pass, driver, true);
        } else {
            com = constructCmdUrl(url, user, driver, false);
            comForDebug = constructCmdUrl(url, user, driver, true);
        }
        debug(comForDebug);
        return dispatch(com);
    }
    // load property file
    String propertyFile = cl.getOptionValue("property-file");
    if (propertyFile != null) {
        try {
            this.consoleReader = new ConsoleReader();
        } catch (IOException e) {
            handleException(e);
        }
        if (!dispatch("!properties " + propertyFile)) {
            exit = true;
            return false;
        }
    }
    return false;
}
Also used : ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException) Properties(java.util.Properties)

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