Commit 19d0fef6 authored by Eric Duminil's avatar Eric Duminil
Browse files

CLI get version.

parent 7c561a53
......@@ -9,8 +9,10 @@
import java.util.Scanner;
import java.util.concurrent.Callable;
import org.osgeo.proj4j.CoordinateReferenceSystem;
import eu.simstadt.regionchooser.RegionChooserCLI.GetVersion;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.IVersionProvider;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.Spec;
......@@ -41,17 +43,14 @@
// --wkt ./grombuhl.txt
@Command(name = "region_chooser", mixinStandardHelpOptions = true, version = "regionChooser 0.2.9", description = "Extracts a region from one or more citygmls.", sortOptions = false)
@Command(name = "region_chooser", mixinStandardHelpOptions = true, description = "Extracts a region from one or more citygmls.", sortOptions = false, versionProvider = GetVersion.class)
class RegionChooserCLI implements Callable<Integer>
{
@Spec
CommandSpec spec;
//TODO: Add --gui?
@Option(names = { "-i",
"--input" }, required = true, split = ",", description = "Citygml files to extract from", paramLabel = "input.gml")
//TODO: Allow folders too?
Path[] citygmls;
@Option(names = { "-o",
......@@ -122,6 +121,13 @@ public Integer call() throws Exception {
return 0;
}
// this example implements Callable, so parsing, error handling and handling user
// requests for usage help or version help can be done with one line of code.
public static void main(String... args) {
int exitCode = new CommandLine(new RegionChooserCLI()).execute(args);
System.exit(exitCode);
}
private void logInfo(String message) {
spec.commandLine().getErr().println(message);
}
......@@ -132,10 +138,12 @@ private static String getInput() {
}
}
// this example implements Callable, so parsing, error handling and handling user
// requests for usage help or version help can be done with one line of code.
public static void main(String... args) {
int exitCode = new CommandLine(new RegionChooserCLI()).execute(args);
System.exit(exitCode);
static class GetVersion implements IVersionProvider
{
@Override
public String[] getVersion() throws Exception {
return new String[] { RegionChooserUtils.getApplicationVersion() };
}
}
}
\ No newline at end of file
......@@ -59,6 +59,7 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
for (int i = 0; i < citygmlPaths.length; i++) {
Path citygmlPath = citygmlPaths[i];
LOGGER.info("Parsing " + citygmlPath);
//TODO: Allow citygmlPath for folders too, and iterate over gmls?
citygml = new CityGmlIterator(citygmlPath);
for (BuildingXmlNode buildingXmlNode : citygml) {
if (buildingsCount == 0) {
......
......@@ -57,6 +57,13 @@ void testNoInput() {
assertTrue(err.toString().contains(expectedErr), err.toString() + " should contain " + expectedErr);
}
@Test
void testGetVersion() {
new CommandLine(new RegionChooserCLI()).execute("--version");
String expectedVersion = RegionChooserUtils.getApplicationVersion();
assertTrue(out.toString().contains(expectedVersion), out.toString() + " should contain " + expectedVersion);
}
@Test
void testExtractRegionFromTwoCitygmls() throws IOException {
String wktPolygon = "POLYGON((3512984.7003764412 5405148.310572891,3513038.6360455155 5405010.072163861,3513142.7277745553 5405004.02571992,3514204.1661769524 5405563.192081669,3514399.2818417274 5405720.905457244,3514291.6158155007 5405896.706492759,3512984.7003764412 5405148.310572891))";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment