public static void runFromCsv(String csvFile) throws IOException { List<String[]> exercises; try (CSVReader reader = new CSVReader(new FileReader(csvFile))) { exercises = reader.readAll(); } while (true) { for (String[] exercise : exercises) { if (exercise.length < 2) continue; if (exercise[0].startsWith("#")) continue; LOGGER.info("Running {} for {}", exercise[0], exercise[1]); String[] arguments = Arrays.copyOfRange(exercise, 2, exercise.length); Exercise.runExercise(exercise[0], Long.parseLong(exercise[1]), arguments); } } }
public static void main(String[] args) throws ParseException, IOException { Options options = new Options(); options.addOption("f", true, "csv file to use for exercises"); options.addOption("c", true, "single class to run"); options.addOption("t", true, "time limit to run for"); CommandLine cmd = new GnuParser().parse(options, args); if (cmd.hasOption("f")) { runFromCsv(cmd.getOptionValue("f")); } else if (cmd.hasOption("c")) { String exercise = cmd.getOptionValue("c"); long timeLimit = Long.parseLong(cmd.getOptionValue("t")); Exercise.runExercise(exercise, timeLimit, new String[0]); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Main", options); } }