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);
}
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;
}
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();
}
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);
}
}
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.");
}
Aggregations