diff --git a/onebusaway-gtfs-merge-cli/src/main/java/org/onebusaway/gtfs_merge/GtfsMergerMain.java b/onebusaway-gtfs-merge-cli/src/main/java/org/onebusaway/gtfs_merge/GtfsMergerMain.java index 564b69665..2d273ef79 100644 --- a/onebusaway-gtfs-merge-cli/src/main/java/org/onebusaway/gtfs_merge/GtfsMergerMain.java +++ b/onebusaway-gtfs-merge-cli/src/main/java/org/onebusaway/gtfs_merge/GtfsMergerMain.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -55,20 +54,20 @@ public class GtfsMergerMain { * Generic Arguments ****/ - private static CommandLineParser _parser = new PosixParser(); + private static final CommandLineParser _parser = new PosixParser(); - private Options _options = new Options(); + private final Options options = new Options(); /** * Mapping from GTFS file name to the entity type handled by that class. */ - private Map> _entityClassesByFilename = new HashMap>(); + private final Map> _entityClassesByFilename = new HashMap<>(); /** * If we ever need to register a custom option handler for a specific entity * type, we would do it here. */ - private Map, OptionHandler> _optionHandlersByEntityClass = new HashMap, OptionHandler>(); + private final Map, OptionHandler> _optionHandlersByEntityClass = new HashMap<>(); public static void main(String[] args) throws IOException { GtfsMergerMain m = new GtfsMergerMain(); @@ -76,7 +75,7 @@ public static void main(String[] args) throws IOException { } public GtfsMergerMain() { - buildOptions(_options); + buildOptions(options); mapEntityClassesToFilenames(); } @@ -92,12 +91,9 @@ public void run(String[] args) throws IOException { } try { - CommandLine cli = _parser.parse(_options, args, true); - runApplication(cli, args); - } catch (MissingOptionException ex) { - System.err.println("Missing argument: " + ex.getMessage()); - printHelp(); - } catch (MissingArgumentException ex) { + CommandLine cli = _parser.parse(options, args, true); + runApplication(cli); + } catch (MissingOptionException | MissingArgumentException ex) { System.err.println("Missing argument: " + ex.getMessage()); printHelp(); } catch (UnrecognizedOptionException ex) { @@ -128,11 +124,11 @@ protected void buildOptions(Options options) { "error on dropped duplicates"); } - protected void printHelp(PrintWriter out, Options options) throws IOException { + protected void printHelp() throws IOException { InputStream is = getClass().getResourceAsStream("usage.txt"); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - String line = null; + String line; while ((line = reader.readLine()) != null) { System.err.println(line); @@ -141,7 +137,7 @@ protected void printHelp(PrintWriter out, Options options) throws IOException { reader.close(); } - protected void runApplication(CommandLine cli, String[] originalArgs) + protected void runApplication(CommandLine cli) throws Exception { String[] args = cli.getArgs(); @@ -164,14 +160,6 @@ protected void runApplication(CommandLine cli, String[] originalArgs) merger.run(inputPaths, outputPath); } - /***************************************************************************** - * Protected Methods - ****************************************************************************/ - - protected void printHelp() throws IOException { - printHelp(new PrintWriter(System.err, true), _options); - } - private boolean needsHelp(String[] args) { for (String arg : args) { if (arg.equals("-h") || arg.equals("--help") || arg.equals("-help")) diff --git a/onebusaway-gtfs-transformer-cli/pom.xml b/onebusaway-gtfs-transformer-cli/pom.xml index 57d18a8bc..4b1f5113e 100644 --- a/onebusaway-gtfs-transformer-cli/pom.xml +++ b/onebusaway-gtfs-transformer-cli/pom.xml @@ -21,7 +21,7 @@ commons-cli commons-cli - 1.2 + 1.9.0 org.slf4j diff --git a/onebusaway-gtfs-transformer-cli/src/main/java/org/onebusaway/gtfs_transformer/GtfsTransformerMain.java b/onebusaway-gtfs-transformer-cli/src/main/java/org/onebusaway/gtfs_transformer/GtfsTransformerMain.java index a1e107933..a12183854 100644 --- a/onebusaway-gtfs-transformer-cli/src/main/java/org/onebusaway/gtfs_transformer/GtfsTransformerMain.java +++ b/onebusaway-gtfs-transformer-cli/src/main/java/org/onebusaway/gtfs_transformer/GtfsTransformerMain.java @@ -147,29 +147,29 @@ public void run(String[] args) throws IOException { protected void buildOptions(Options options) { - options.addOption(ARG_AGENCY_ID, true, "agency id"); - - options.addOption(ARG_MODIFICATIONS, true, "data modifications"); - options.addOption(ARG_TRANSFORM, true, "data transformation"); - options.addOption(ARG_REFERENCE, true, "reference GTFS to merge from"); - options.addOption(ARG_STOP_MAPPING, true, "Stop Name Mapping File"); - options.addOption(ARG_IGNORE_STOPS, true, "List of stops names to ignore"); - options.addOption(ARG_REGEX_FILE, true, "Regex pattern mapping file"); - options.addOption(ARG_CONTROL_FILE, true, "file to remap stop ids and other properties"); - options.addOption(ARG_CONCURRENCY_FILE, true, "file to remap wrong way concurrencies"); - options.addOption(ARG_OMNY_ROUTES_FILE, true, "file to add OMNY enabled routes to GTFS"); - options.addOption(ARG_OMNY_STOPS_FILE, true, "file to add OMNY enabled stops to GTFS"); - options.addOption(ARG_VERIFY_ROUTES_FILE, true, "file to check route names vs route ids in GTFS"); - - options.addOption(ARG_LOCAL_VS_EXPRESS, false, + options.addOption(null, ARG_AGENCY_ID, true, "agency id"); + + options.addOption(null, ARG_MODIFICATIONS, true, "data modifications"); + options.addOption(null, ARG_TRANSFORM, true, "data transformation"); + options.addOption(null, ARG_REFERENCE, true, "reference GTFS to merge from"); + options.addOption(null, ARG_STOP_MAPPING, true, "Stop Name Mapping File"); + options.addOption(null, ARG_IGNORE_STOPS, true, "List of stops names to ignore"); + options.addOption(null, ARG_REGEX_FILE, true, "Regex pattern mapping file"); + options.addOption(null, ARG_CONTROL_FILE, true, "file to remap stop ids and other properties"); + options.addOption(null, ARG_CONCURRENCY_FILE, true, "file to remap wrong way concurrencies"); + options.addOption(null, ARG_OMNY_ROUTES_FILE, true, "file to add OMNY enabled routes to GTFS"); + options.addOption(null, ARG_OMNY_STOPS_FILE, true, "file to add OMNY enabled stops to GTFS"); + options.addOption(null, ARG_VERIFY_ROUTES_FILE, true, "file to check route names vs route ids in GTFS"); + + options.addOption(null, ARG_LOCAL_VS_EXPRESS, false, "add additional local vs express fields"); - options.addOption(ARG_CHECK_STOP_TIMES, false, + options.addOption(null, ARG_CHECK_STOP_TIMES, false, "check stop times are in order"); - options.addOption(ARG_REMOVE_REPEATED_STOP_TIMES, false, + options.addOption(null, ARG_REMOVE_REPEATED_STOP_TIMES, false, "remove repeated stop times"); - options.addOption(ARG_REMOVE_DUPLICATE_TRIPS, false, + options.addOption(null, ARG_REMOVE_DUPLICATE_TRIPS, false, "remove duplicate trips"); - options.addOption(ARG_OVERWRITE_DUPLICATES, false, + options.addOption(null, ARG_OVERWRITE_DUPLICATES, false, "overwrite duplicate elements"); } @@ -210,7 +210,7 @@ protected void runApplication(CommandLine cli, String[] originalArgs) for (Option option : options) { - String name = option.getOpt(); + String name = option.getLongOpt(); if (name.equals(ARG_REMOVE_REPEATED_STOP_TIMES)) configureRemoveRepeatedStopTimes(transformer); @@ -281,11 +281,11 @@ private Option[] getOptionsInCommandLineOrder(CommandLine cli, String[] originalArgs) { Option[] options = cli.getOptions(); - List> orderedOptions = new ArrayList>(); + List> orderedOptions = new ArrayList<>(); for (Option option : options) { - String argName = option.getOpt(); + String argName = option.getLongOpt(); int optionPosition = originalArgs.length; for (int i = 0; i < originalArgs.length; i++) { @@ -295,7 +295,7 @@ private Option[] getOptionsInCommandLineOrder(CommandLine cli, } } - orderedOptions.add(new Ordered