Search in sources :

Example 1 with ConsoleReader

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

the class BeeLine method begin.

/**
   * Start accepting input from stdin, and dispatch it
   * to the appropriate {@link CommandHandler} until the
   * global variable <code>exit</code> is true.
   */
public int begin(String[] args, InputStream inputStream) throws IOException {
    try {
        // load the options first, so we can override on the command line
        getOpts().load();
    } catch (Exception e) {
    // nothing
    }
    setupHistory();
    //add shutdown hook to cleanup the beeline for smooth exit
    addBeelineShutdownHook();
    //this method also initializes the consoleReader which is
    //needed by initArgs for certain execution paths
    ConsoleReader reader = initializeConsoleReader(inputStream);
    if (isBeeLine) {
        int code = initArgs(args);
        if (code != 0) {
            return code;
        }
    } else {
        int code = initArgsFromCliVars(args);
        if (code != 0 || exit) {
            return code;
        }
        defaultConnect(false);
    }
    if (getOpts().isHelpAsked()) {
        return 0;
    }
    if (getOpts().getScriptFile() != null) {
        return executeFile(getOpts().getScriptFile());
    }
    try {
        info(getApplicationTitle());
    } catch (Exception e) {
    // ignore
    }
    return execute(reader, false);
}
Also used : ConsoleReader(jline.console.ConsoleReader) TTransportException(org.apache.thrift.transport.TTransportException) BeelineHS2ConnectionFileParseException(org.apache.hive.beeline.hs2connection.BeelineHS2ConnectionFileParseException) EOFException(java.io.EOFException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParseException(org.apache.commons.cli.ParseException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 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) {
        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)

Example 3 with ConsoleReader

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

the class CliDriver method setupConsoleReader.

protected void setupConsoleReader() throws IOException {
    reader = new ConsoleReader();
    reader.setExpandEvents(false);
    reader.setBellEnabled(false);
    for (Completer completer : getCommandCompleter()) {
        reader.addCompleter(completer);
    }
    setupCmdHistory();
}
Also used : ConsoleReader(jline.console.ConsoleReader) Completer(jline.console.completer.Completer) StringsCompleter(jline.console.completer.StringsCompleter) ArgumentCompleter(jline.console.completer.ArgumentCompleter)

Example 4 with ConsoleReader

use of jline.console.ConsoleReader in project grails-core by grails.

the class GrailsConsole method createConsoleReader.

protected ConsoleReader createConsoleReader(InputStream systemIn) throws IOException {
    // need to swap out the output to avoid logging during init
    final PrintStream nullOutput = new PrintStream(new ByteArrayOutputStream());
    final PrintStream originalOut = Log.getOutput();
    try {
        Log.setOutput(nullOutput);
        ConsoleReader consoleReader = new ConsoleReader(systemIn, out);
        consoleReader.setExpandEvents(false);
        return consoleReader;
    } finally {
        Log.setOutput(originalOut);
    }
}
Also used : GrailsConsoleErrorPrintStream(org.grails.build.logging.GrailsConsoleErrorPrintStream) GrailsConsolePrintStream(org.grails.build.logging.GrailsConsolePrintStream) ConsoleReader(jline.console.ConsoleReader)

Example 5 with ConsoleReader

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

the class ApexCliTest method testMergeAppFromConfigAndAppPackage.

@Test
public void testMergeAppFromConfigAndAppPackage() throws Exception {
    ApexCli.LaunchCommandLineInfo commandLineInfo = ApexCli.getLaunchCommandLineInfo(new String[] { "-conf", configFile.getAbsolutePath(), appFile.getAbsolutePath(), "-useConfigApps", "inclusive" });
    Assert.assertEquals("configApps", "inclusive", commandLineInfo.useConfigApps);
    ApexCli apexCli = new ApexCli();
    apexCli.init();
    try {
        apexCli.getLaunchAppPackageArgs(ap, cp, commandLineInfo, new ConsoleReader());
    } catch (ApexCli.CliException cliException) {
        return;
    }
    Assert.fail("Cli failed throw multiple apps exception.");
}
Also used : ConsoleReader(jline.console.ConsoleReader) Test(org.junit.Test)

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