-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add command-line flag --output and closes #5
- Loading branch information
Showing
4 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,6 @@ | |
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.regex.Pattern; | ||
|
||
public class Main { | ||
private static String PROGRAM_NAME = "osmparser"; | ||
|
@@ -17,6 +14,7 @@ public static void main(String[] args) throws IOException { | |
Options options = createOptions(); | ||
|
||
CommandLine cmd = null; | ||
|
||
try { | ||
cmd = parser.parse(options, args); | ||
} catch (ParseException ex) { | ||
|
@@ -43,8 +41,14 @@ public static void main(String[] args) throws IOException { | |
info("Excluded tags: " + Arrays.asList(excludedTags)); | ||
} | ||
|
||
String[] output = cmd.getOptionValues("output"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
if(notQuiet && output[0] != null) { | ||
info("Output file name: " + output[0]); | ||
} | ||
|
||
try { | ||
createOsmparser(files, includedTags, excludedTags).start(); | ||
createOsmparser(files, output, includedTags, excludedTags).start(); | ||
} catch (RuntimeException ex) { | ||
if (!(ex.getCause() instanceof IOException)) { | ||
throw ex; | ||
|
@@ -71,17 +75,18 @@ private static WayTag[] parseWayTagsFromOptions(String[] optionValues) { | |
return tags; | ||
} | ||
|
||
private static Osmparser createOsmparser(String[] files, WayTag[] includeWays, WayTag[] excludeWays) { | ||
private static Osmparser createOsmparser(String[] files, String[] output, WayTag[] includeWays, WayTag[] excludeWays) { | ||
StreamingXmlGraphParser graphParser = new StreamingXmlGraphParser(includeWays, excludeWays); | ||
return new Osmparser(files, "graph.json", graphParser); | ||
if(output[0] == null) return new Osmparser(files, "graph.json", graphParser); | ||
return new Osmparser(files, output[0], graphParser); | ||
} | ||
|
||
private static Options createOptions() { | ||
Options options = new Options(); | ||
|
||
Option files = Option.builder("f") | ||
.longOpt("files") | ||
.desc("the XML map files to be parsed") | ||
.desc("the osm (xml) map files to be parsed") | ||
.hasArgs() | ||
.required() | ||
.build(); | ||
|
@@ -107,6 +112,12 @@ private static Options createOptions() { | |
.build(); | ||
options.addOption(excludeWays); | ||
|
||
Option output = Option.builder("o") | ||
.longOpt("output") | ||
.desc("output file name") | ||
.hasArgs() | ||
This comment has been minimized.
Sorry, something went wrong.
cxcorp
Contributor
|
||
.build(); | ||
options.addOption(output); | ||
return options; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ public class Osmparser { | |
|
||
public Osmparser(String[] mapFiles, String outFile, GraphParser graphParser) { | ||
this.mapFiles = mapFiles; | ||
if(!outFile.endsWith(".json")) outFile += ".json"; | ||
This comment has been minimized.
Sorry, something went wrong.
cxcorp
Contributor
|
||
this.outFile = outFile; | ||
this.parser = graphParser; | ||
} | ||
|
After changing the option builder call from
.hasArgs()
to.hasArg()
, this should probably be changed tocmd.getOptionValue
since only one value is supported anyways.