use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class Diff method runInternal.
/**
* Executes the diff command with the specified options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
checkParameter(refSpec.size() <= 2, "Commit list is too long :%s", refSpec);
checkParameter(!(nogeom && summary), "Only one printing mode allowed");
checkParameter(!(bounds && count), "Only one of --bounds or --count is allowed");
checkParameter(!(cached && refSpec.size() > 1), "--cached allows zero or one ref specs to compare the index with.");
GeoGIG geogig = cli.getGeogig();
String oldVersion = resolveOldVersion();
String newVersion = resolveNewVersion();
List<String> paths = removeEmptyPaths();
if (bounds) {
DiffBounds diff = geogig.command(DiffBounds.class).setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
diff.setPathFilters(paths);
CoordinateReferenceSystem crs = parseCrs();
if (crs != null) {
diff.setCRS(crs);
}
DiffSummary<BoundingBox, BoundingBox> diffBounds = diff.call();
BoundsDiffPrinter.print(geogig, cli.getConsole(), diffBounds);
return;
}
if (count) {
if (oldVersion == null) {
oldVersion = Ref.HEAD;
}
if (newVersion == null) {
newVersion = cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD;
}
DiffCount cdiff = geogig.command(DiffCount.class).setOldVersion(oldVersion).setNewVersion(newVersion);
cdiff.setFilter(paths);
DiffObjectCount count = cdiff.call();
ConsoleReader console = cli.getConsole();
console.println(String.format("Trees changed: %d, features changed: %,d", count.treeCount(), count.featureCount()));
console.flush();
return;
}
DiffOp diff = geogig.command(DiffOp.class);
diff.setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
Iterator<DiffEntry> entries;
if (paths.isEmpty()) {
entries = diff.setProgressListener(cli.getProgressListener()).call();
} else {
entries = Iterators.emptyIterator();
for (String path : paths) {
Iterator<DiffEntry> moreEntries = diff.setFilter(path).setProgressListener(cli.getProgressListener()).call();
entries = Iterators.concat(entries, moreEntries);
}
}
if (!entries.hasNext()) {
cli.getConsole().println("No differences found");
return;
}
DiffPrinter printer;
if (summary) {
printer = new SummaryDiffPrinter();
} else {
printer = new FullDiffPrinter(nogeom, false);
}
DiffEntry entry;
while (entries.hasNext()) {
entry = entries.next();
printer.print(geogig, cli.getConsole(), entry);
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class RebuildGraph method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
ImmutableList<ObjectId> updatedObjects = cli.getGeogig().command(RebuildGraphOp.class).call();
final ConsoleReader console = cli.getConsole();
if (updatedObjects.size() > 0) {
if (quiet) {
console.println(updatedObjects.size() + " graph elements (commits) were fixed.");
} else {
console.println("The following graph elements (commits) were incomplete or missing and have been fixed:");
for (ObjectId object : updatedObjects) {
console.println(object.toString());
}
}
} else {
console.println("No missing or incomplete graph elements (commits) were found.");
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class RevParse method runInternal.
/**
* Executes the rev-parse command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
GeoGIG geogig = cli.getGeogig();
if (!refSpecs.isEmpty()) {
checkParameter(!(resolve_geogig_dir || is_inside_work_tree), "if refSpec is given, --resolve-geogig-dir or --is-inside-work-tree shall not be specified");
ConsoleReader console = cli.getConsole();
for (String refSpec : this.refSpecs) {
Optional<ObjectId> resolved = geogig.command(org.locationtech.geogig.api.plumbing.RevParse.class).setRefSpec(refSpec).call();
checkParameter(resolved.isPresent(), "fatal: ambiguous argument '%s': " + "unknown revision or path not in the working tree.", refSpec);
console.println(resolved.get().toString());
}
console.flush();
return;
}
boolean closeIt = false;
if (null == geogig) {
geogig = cli.newGeoGIG(Hints.readOnly());
closeIt = true;
}
try {
if (resolve_geogig_dir) {
resolveGeogigDir(cli.getConsole(), geogig);
} else if (is_inside_work_tree) {
isInsideWorkTree(cli.getConsole(), geogig);
}
} finally {
if (closeIt) {
geogig.close();
}
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class GeogigCLI method printShortCommandList.
/**
* This prints out only porcelain commands
*
* @param mainCommander
*
* @throws IOException
*/
public void printShortCommandList(JCommander mainCommander) {
TreeSet<String> commandNames = Sets.newTreeSet();
int longestCommandLenght = 0;
// do this to ignore aliases
for (String name : mainCommander.getCommands().keySet()) {
JCommander command = mainCommander.getCommands().get(name);
Class<? extends Object> clazz = command.getObjects().get(0).getClass();
String packageName = clazz.getPackage().getName();
if (!packageName.startsWith("org.locationtech.geogig.cli.plumbing")) {
commandNames.add(name);
longestCommandLenght = Math.max(longestCommandLenght, name.length());
}
}
ConsoleReader console = getConsole();
try {
console.println("usage: geogig <command> [<args>]");
console.println();
console.println("The most commonly used geogig commands are:");
for (String cmd : commandNames) {
console.print(Strings.padEnd(cmd, longestCommandLenght, ' '));
console.print("\t");
console.println(mainCommander.getCommandDescription(cmd));
}
console.flush();
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class GeogigCLI method printCommandList.
/**
* This prints out all commands, including plumbing ones, without description
*
* @param mainCommander
* @throws IOException
*/
public void printCommandList(JCommander mainCommander) {
TreeSet<String> commandNames = Sets.newTreeSet();
int longestCommandLenght = 0;
// do this to ignore aliases
for (String name : mainCommander.getCommands().keySet()) {
commandNames.add(name);
longestCommandLenght = Math.max(longestCommandLenght, name.length());
}
ConsoleReader console = getConsole();
try {
console.println("usage: geogig <command> [<args>]");
console.println();
int i = 0;
for (String cmd : commandNames) {
console.print(Strings.padEnd(cmd, longestCommandLenght, ' '));
i++;
if (i % 3 == 0) {
console.println();
} else {
console.print("\t");
}
}
console.flush();
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
Aggregations