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