diff --git a/pom.xml b/pom.xml index 7aecf17a04bb3ef14e1085f758308e2af52d76c9..676b7e84c8ee09f9bb7e471d8156992192f237ac 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,12 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>info.picocli</groupId> + <artifactId>picocli</artifactId> + <version>4.6.3</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.osgeo/proj4j --> <dependency> <groupId>org.osgeo</groupId> diff --git a/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java b/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java index 3d6c73a2473f4aa756fe2b130928ea37aef391b1..00b0df42f39327d948d6d0f06121f6f9b7e2851b 100644 --- a/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java +++ b/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java @@ -1,48 +1,37 @@ package eu.simstadt.regionchooser; -import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.logging.Logger; -import java.util.stream.Stream; +import java.util.List; +import java.util.concurrent.Callable; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Parameters; -/* - * Utility class to launch RegionChooser without GUI. - */ -public class RegionChooserCommandLineInterface +@Command(name = "region_chooser", mixinStandardHelpOptions = true, version = "regionChooser x.x", description = "Extracts a region from one or more citygmls.") +class RegionChooserCommandLineInterface implements Callable<Integer> { - private static final Logger LOGGER = Logger.getLogger(RegionChooserCommandLineInterface.class.getName()); + @Parameters(index = "0", description = "SRS Name : 'EPSG:31467' or just 31467") + String srsName; - public static void main(String[] args) throws IOException { - LOGGER.info(String.format("Launching RegionChooser %s", RegionChooserUtils.getApplicationVersion())); - if (args.length == 0) { - displayInfoAndQuit(); - } + @Parameters(index = "1", description = "Output file : output.gml") + Path outputCityGML; - Path[] paths = Stream.of(args).map(Paths::get).toArray(Path[]::new); - for (Path path : paths) { - System.out.println(path); - } - //TODO: Also get output file - //TODO: Also get EPSG - //TODO: Also get WKT polygon + @Parameters(index = "2..*", arity = "1..*", description = "The citygml files to extract from : input1.gml input2.gml") + List<Path> citygmls; - // StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, srsName, paths); - // - // File buildingIdsFile = selectSaveFileWithDialog(project, - // csvCitygmls.replace(";", "_").replace(".gml", ""), "selected_region"); - // RegionChooserUtils.writeStringBuilderToFile(sb, buildingIdsFile.toPath()); + @Override + public Integer call() throws Exception { // your business logic goes here... + for (Path file : citygmls) { + System.out.println(file); + } + return 0; } - private static void displayInfoAndQuit() { - LOGGER.info( - "Please add one directory path as argument. Either a repository path in order to list the available projects:\n" - + " java -d64 -classpath lib/*;workflows/* eu.simstadt.desktop.SimStadtCommandLineInterface ..\\TestRepository\n" - + "Or a project path in order to list the available workflows:\n" - + " java -d64 -classpath lib/*;workflows/* eu.simstadt.desktop.SimStadtCommandLineInterface ..\\TestRepository\\Gruenbuehl.proj\n" - + "Or a workflow path in order to launch the workflow:\n" - + " java -d64 -classpath lib/*;workflows/* eu.simstadt.desktop.SimStadtCommandLineInterface ..\\TestRepository\\Gruenbuehl.proj\\a.step"); - System.exit(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 RegionChooserCommandLineInterface()).execute(args); + System.exit(exitCode); } -} +} \ No newline at end of file