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 grakn by graknlabs.
the class GraqlConsole method start.
public static boolean start(GraqlShellOptions options, SessionProvider sessionProvider, String historyFile, PrintStream sout, PrintStream serr) throws InterruptedException, IOException {
List<String> queries = null;
// ------- Check option ------------------------
String query = options.getQuery();
// This is a best-effort guess as to whether the user has made a mistake, without parsing the query
if (query != null) {
queries = ImmutableList.of(query);
if (!query.contains("$") && query.trim().startsWith("match")) {
serr.println(ErrorMessage.NO_VARIABLE_IN_QUERY.getMessage());
}
}
// Print usage message if requested or if invalid arguments provided
if (options.displayHelp()) {
options.printUsage(sout);
return true;
}
if (options.displayVersion()) {
sout.println(GraknVersion.VERSION);
return true;
}
// ------- Check option ------------------------
Path path = options.getBatchLoadPath();
if (path != null) {
Keyspace keyspace = options.getKeyspace();
SimpleURI location = options.getUri();
SimpleURI httpUri = location != null ? location : Grakn.DEFAULT_URI;
try {
BatchLoader.sendBatchRequest(httpUri, keyspace, path, sout, serr);
} catch (Exception e) {
sout.println("Batch failed \n" + CommonUtil.simplifyExceptionMessage(e));
return false;
}
return true;
}
// -------- If no option set we start GraqlShell ----------
OutputFormat outputFormat = options.getOutputFormat();
boolean infer = options.shouldInfer();
ConsoleReader console = new ConsoleReader(System.in, sout);
GraknSession session = sessionProvider.getSession(options, console);
try (GraqlShell shell = new GraqlShell(historyFile, session, console, serr, outputFormat, infer)) {
List<Path> filePaths = options.getFiles();
if (filePaths != null) {
queries = loadQueries(filePaths);
}
// Start shell
shell.start(queries);
return !shell.errorOccurred();
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode().equals(Status.Code.UNAVAILABLE)) {
serr.println(ErrorMessage.COULD_NOT_CONNECT.getMessage());
return false;
} else {
throw e;
}
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class OracleDescribeTest method testFlushException.
@Test
public void testFlushException() throws Exception {
ConsoleReader consoleReader = spy(new ConsoleReader(System.in, System.out, new UnsupportedTerminal()));
GeogigCLI testCli = new GeogigCLI(consoleReader);
setUpGeogig(testCli);
doThrow(new IOException("Exception")).when(consoleReader).flush();
OracleDescribe describeCommand = new OracleDescribe();
describeCommand.table = "table1";
describeCommand.dataStoreFactory = TestHelper.createTestFactory();
exception.expect(Exception.class);
describeCommand.run(testCli);
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class OracleDescribeTest method setUp.
@Before
public void setUp() throws Exception {
ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
cli = new GeogigCLI(consoleReader);
setUpGeogig(cli);
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class OracleListTest 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"));
OracleList listCommand = new OracleList();
listCommand.dataStoreFactory = TestHelper.createTestFactory();
exception.expect(MockitoException.class);
listCommand.run(mockCli);
}
Aggregations