use of jline.console.ConsoleReader in project apex-core by apache.
the class ApexCli method run.
public void run() throws IOException {
ConsoleReader reader = new ConsoleReader();
reader.setExpandEvents(false);
reader.setBellEnabled(false);
try {
processSourceFile(StramClientUtils.getConfigDir() + "/clirc_system", reader);
} catch (Exception ex) {
// ignore
}
try {
processSourceFile(StramClientUtils.getUserDTDirectory() + "/clirc", reader);
} catch (Exception ex) {
// ignore
}
if (consolePresent) {
printWelcomeMessage();
setupCompleter(reader);
setupHistory(reader);
//reader.setHandleUserInterrupt(true);
} else {
reader.setEchoCharacter((char) 0);
}
setupAgents();
String line;
PrintWriter out = new PrintWriter(System.out);
int i = 0;
while (true) {
if (commandsToExecute != null) {
if (i >= commandsToExecute.length) {
break;
}
line = commandsToExecute[i++];
} else {
line = readLine(reader);
if (line == null) {
break;
}
}
processLine(line, reader, true);
out.flush();
}
if (topLevelHistory != null) {
try {
topLevelHistory.flush();
} catch (IOException ex) {
LOG.warn("Cannot flush command history", ex);
}
}
if (changingLogicalPlanHistory != null) {
try {
changingLogicalPlanHistory.flush();
} catch (IOException ex) {
LOG.warn("Cannot flush command history", ex);
}
}
if (consolePresent) {
System.out.println("exit");
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class Apply 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();
GeoGIG geogig = cli.getGeogig();
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 CommandFailedException("Can't open patch file " + patchFile, e1);
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
} catch (UnsupportedEncodingException e) {
Closeables.closeQuietly(reader);
Closeables.closeQuietly(stream);
throw new CommandFailedException("Error reading patch file " + patchFile, e);
}
Patch patch = PatchSerializer.read(reader);
Closeables.closeQuietly(reader);
Closeables.closeQuietly(stream);
if (reverse) {
patch = patch.reversed();
}
if (summary) {
console.println(patch.toString());
} else if (check) {
VerifyPatchResults verify = cli.getGeogig().command(VerifyPatchOp.class).setPatch(patch).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());
}
} else {
try {
Patch rejected = geogig.command(ApplyPatchOp.class).setPatch(patch).setApplyPartial(reject).call();
if (reject) {
if (rejected.isEmpty()) {
console.println("Patch applied succesfully");
} else {
int accepted = patch.count() - rejected.count();
StringBuilder sb = new StringBuilder();
File file = new File(patchFile.getAbsolutePath() + ".rej");
sb.append("Patch applied only partially.\n");
sb.append(Integer.toString(accepted) + " changes were applied.\n");
sb.append(Integer.toString(rejected.count()) + " changes were rejected.\n");
BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
PatchSerializer.write(writer, patch);
writer.flush();
writer.close();
sb.append("Patch file with rejected changes created at " + file.getAbsolutePath() + "\n");
throw new CommandFailedException(sb.toString());
}
} else {
console.println("Patch applied succesfully");
}
} catch (CannotApplyPatchException e) {
throw new CommandFailedException(e);
}
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class Branch method runInternal.
@Override
public void runInternal(final GeogigCLI cli) throws IOException {
final GeoGIG geogig = cli.getGeogig();
final ConsoleReader console = cli.getConsole();
if (delete) {
checkParameter(!branchName.isEmpty(), "no name specified for deletion");
for (String br : branchName) {
Optional<? extends Ref> deletedBranch;
deletedBranch = geogig.command(BranchDeleteOp.class).setName(br).call();
checkParameter(deletedBranch.isPresent(), "No branch called '%s'.", br);
console.println(String.format("Deleted branch '%s'.", br));
}
return;
}
checkParameter(branchName.size() < 3, "too many arguments: %s", branchName);
if (rename) {
checkParameter(!branchName.isEmpty(), "You must specify a branch to rename.");
if (branchName.size() == 1) {
Optional<Ref> headRef = geogig.command(RefParse.class).setName(Ref.HEAD).call();
geogig.command(BranchRenameOp.class).setNewName(branchName.get(0)).setForce(force).call();
if (headRef.isPresent()) {
SymRef ref = (SymRef) headRef.get();
console.println("renamed branch '" + ref.getTarget().substring(Ref.HEADS_PREFIX.length()) + "' to '" + branchName.get(0) + "'");
}
} else {
geogig.command(BranchRenameOp.class).setOldName(branchName.get(0)).setNewName(branchName.get(1)).setForce(force).call();
console.println("renamed branch '" + branchName.get(0) + "' to '" + branchName.get(1) + "'");
}
return;
}
if (branchName.isEmpty()) {
listBranches(cli);
return;
}
final String branch = branchName.get(0);
final String origin = branchName.size() > 1 ? branchName.get(1) : Ref.HEAD;
Ref newBranch = geogig.command(BranchCreateOp.class).setName(branch).setForce(force).setOrphan(orphan).setAutoCheckout(checkout).setSource(origin).call();
console.println("Created branch " + newBranch.getName());
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class Checkout method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
final GeoGIG geogig = cli.getGeogig();
checkParameter(branchOrStartPoint.size() != 0 || !paths.isEmpty(), "no branch or paths specified");
checkParameter(branchOrStartPoint.size() < 2, "too many arguments");
try {
final ConsoleReader console = cli.getConsole();
String branchOrCommit = (branchOrStartPoint.size() > 0 ? branchOrStartPoint.get(0) : null);
CheckoutResult result = geogig.command(CheckoutOp.class).setForce(force).setSource(branchOrCommit).addPaths(paths).setOurs(ours).setTheirs(theirs).call();
switch(result.getResult()) {
case CHECKOUT_LOCAL_BRANCH:
console.println("Switched to branch '" + result.getNewRef().localName() + "'");
break;
case CHECKOUT_REMOTE_BRANCH:
console.println("Branch '" + result.getNewRef().localName() + "' was set up to track remote branch '" + result.getNewRef().localName() + "' from " + result.getRemoteName() + ".");
console.println("Switched to a new branch '" + result.getNewRef().localName() + "'");
break;
case UPDATE_OBJECTS:
console.println("Objects in the working tree were updated to the specifed version.");
break;
case DETACHED_HEAD:
console.println("You are in 'detached HEAD' state. HEAD is now at " + result.getOid().toString().substring(0, 7) + "...");
break;
default:
break;
}
} catch (CheckoutException e) {
switch(e.statusCode) {
case LOCAL_CHANGES_NOT_COMMITTED:
throw new CommandFailedException("Working tree and index are not clean. To overwrite local changes, use the --force option", e);
case UNMERGED_PATHS:
throw new CommandFailedException(e.getMessage(), e);
}
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class Insert method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
ConsoleReader console = cli.getConsole();
geogig = cli.getGeogig();
Iterable<String> lines = null;
if (filepath != null) {
File file = new File(filepath);
checkParameter(file.exists(), "Insert file cannot be found");
lines = Files.readLines(file, Charsets.UTF_8);
} else {
String featuresText = Joiner.on("\n").join(inputs);
lines = Splitter.on("\n").split(featuresText);
}
Map<String, List<Feature>> features = readFeatures(lines);
long count = 0;
for (String key : features.keySet()) {
List<Feature> treeFeatures = features.get(key);
geogig.getRepository().workingTree().insert(key, treeFeatures.iterator(), cli.getProgressListener(), null, treeFeatures.size());
count += treeFeatures.size();
}
console.print(Long.toString(count) + " features successfully inserted.");
}
Aggregations