use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class LsTree method runInternal.
@Override
public void runInternal(final GeogigCLI cli) throws IOException {
String ref;
if (refList.isEmpty()) {
ref = null;
} else {
ref = refList.get(0);
}
Strategy lsStrategy = Strategy.CHILDREN;
if (recursive) {
if (includeTrees) {
lsStrategy = Strategy.DEPTHFIRST;
} else if (onlyTrees) {
lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
} else {
lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
}
} else {
if (onlyTrees) {
lsStrategy = Strategy.TREES_ONLY;
}
}
Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
final ConsoleReader console = cli.getConsole();
Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {
@Override
public CharSequence apply(NodeRef input) {
StringBuilder sb = new StringBuilder();
if (!verbose) {
sb.append(input.path());
} else {
Envelope env = new Envelope();
input.getNode().expand(env);
StringBuilder sbenv = new StringBuilder();
sbenv.append(Double.toString(env.getMinX())).append(";").append(Double.toString(env.getMaxX())).append(";").append(Double.toString(env.getMinY())).append(";").append(Double.toString(env.getMaxY()));
sb.append(input.getMetadataId().toString()).append(' ').append(input.getType().toString().toLowerCase()).append(' ').append(input.objectId().toString()).append(' ').append(input.path()).append(' ').append(sbenv);
if (input.getType().equals(TYPE.TREE)) {
RevTree tree = cli.getGeogig().command(RevObjectParse.class).setObjectId(input.objectId()).call(RevTree.class).get();
sb.append(' ').append(tree.size()).append(' ').append(tree.numTrees());
}
}
return sb;
}
};
Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
while (lines.hasNext()) {
console.println(lines.next());
}
console.flush();
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class GeogigConsole method run.
private void run(final InputStream in, final OutputStream out) throws IOException {
final Terminal terminal;
if (interactive) {
terminal = null;
/* let jline select an appropriate one */
} else {
// no colors in output
terminal = new UnsupportedTerminal();
}
ConsoleReader consoleReader = new ConsoleReader(in, out, terminal);
consoleReader.setAutoprintThreshold(20);
consoleReader.setPaginationEnabled(interactive);
consoleReader.setHistoryEnabled(interactive);
// needed for CTRL+C not to let the console broken
consoleReader.getTerminal().setEchoEnabled(interactive);
final GeogigCLI cli = new GeogigCLI(consoleReader);
if (interactive) {
addCommandCompleter(consoleReader, cli);
} else {
// no progress percent in output
cli.disableProgressListener();
}
GeogigCLI.addShutdownHook(cli);
setPrompt(cli);
cli.close();
try {
runInternal(cli);
} finally {
try {
cli.close();
} finally {
try {
if (terminal != null) {
terminal.restore();
}
consoleReader.shutdown();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class GeogigConsole method runInternal.
private void runInternal(final GeogigCLI cli) throws IOException {
final ConsoleReader consoleReader = cli.getConsole();
while (true) {
String line = consoleReader.readLine();
if (line == null) {
// EOF / CTRL-D
return;
}
if (line.trim().length() == 0) {
continue;
}
if (line.trim().startsWith("#")) {
// comment
continue;
}
String[] args = ArgumentTokenizer.tokenize(line);
if (interactive && args != null && args.length == 1) {
if ("exit".equals(args[0])) {
return;
}
if ("clear".equals(args[0])) {
consoleReader.clearScreen();
consoleReader.redrawLine();
continue;
}
}
cli.execute(args);
// in case HEAD has changed
setPrompt(cli);
cli.close();
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class VerifyPatch method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(patchFiles.size() < 2, "Only one single patch file accepted");
checkParameter(!patchFiles.isEmpty(), "No patch file specified");
ConsoleReader console = cli.getConsole();
File patchFile = new File(patchFiles.get(0));
checkParameter(patchFile.exists(), "Patch file cannot be found");
FileInputStream stream;
try {
stream = new FileInputStream(patchFile);
} catch (FileNotFoundException e1) {
throw new IllegalStateException("Can't open patch file " + patchFile);
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
} catch (UnsupportedEncodingException e) {
Closeables.closeQuietly(reader);
Closeables.closeQuietly(stream);
throw new IllegalStateException("Error reading patch file " + patchFile, e);
}
Patch patch = PatchSerializer.read(reader);
Closeables.closeQuietly(reader);
Closeables.closeQuietly(stream);
VerifyPatchResults verify = cli.getGeogig().command(VerifyPatchOp.class).setPatch(patch).setReverse(reverse).call();
Patch toReject = verify.getToReject();
Patch toApply = verify.getToApply();
if (toReject.isEmpty()) {
console.println("Patch can be applied.");
} else {
console.println("Error: Patch cannot be applied\n");
console.println("Applicable entries:\n");
console.println(toApply.toString());
console.println("\nConflicting entries:\n");
console.println(toReject.toString());
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class WalkGraph method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
String ref;
if (refList.isEmpty()) {
ref = null;
} else {
ref = refList.get(0);
}
Deduplicator deduplicator = cli.getGeogig().command(CreateDeduplicator.class).call();
try {
Iterator<RevObject> iter = //
cli.getGeogig().command(WalkGraphOp.class).setReference(//
ref).setDeduplicator(//
deduplicator).call();
final ConsoleReader console = cli.getConsole();
if (!iter.hasNext()) {
if (ref == null) {
console.println("The working tree is empty");
} else {
console.println("The specified path is empty");
}
return;
}
Function<RevObject, CharSequence> printFunctor = new Function<RevObject, CharSequence>() {
@Override
public CharSequence apply(RevObject input) {
if (verbose) {
return String.format("%s: %s %s", input.getId(), input.getType(), input);
} else {
return String.format("%s: %s", input.getId(), input.getType());
}
}
};
Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
while (lines.hasNext()) {
console.println(lines.next());
}
console.flush();
} finally {
deduplicator.release();
}
}
Aggregations