private static void parseArguments(String[] args) throws ParseException { Options options = new Options(); options.addOption("input", true, "The input file path"); options.addOption("output", true, "The output file path"); options.addOption("threads", true, "The number of threads"); CommandLine commandLine = new PosixParser().parse(options, args); inputFilePath = commandLine.getOptionValue("input", "price_moves.csv"); outputFilePath = commandLine.getOptionValue("output", "result.txt"); numberOfThreads = Integer.valueOf(commandLine.getOptionValue("threads", "1")); }
public static void main(String[] args) throws Exception { long t0 = System.currentTimeMillis(); final String OPT_JAR_FILE = "aijar"; final String OPT_CLASSNAME = "ainame"; Options options = new Options() .addOption( Option.builder(OPT_JAR_FILE) .hasArg() .argName("jarfile") .required() .desc("The path to the jar file") .build()) .addOption( Option.builder(OPT_CLASSNAME) .hasArg() .argName("classname") .required() .desc("The full classpath of the Ai class") .build()) .addOption(timeOpt); DraughtStateParser.addOptions(options); HelpFormatter formatter = new HelpFormatter(); CommandLine line = new DefaultParser().parse(options, args); DraughtsPlayer player; Integer time; DraughtsState draughtsState; try { File aiJar = new File(line.getOptionValue(OPT_JAR_FILE)); if (!aiJar.canRead() || !aiJar.isFile()) { throw new ParseException("Could not read from aijar"); } String className = line.getOptionValue(OPT_CLASSNAME); player = Main.getFromClass(aiJar, className); time = Integer.parseInt(line.getOptionValue(OPT_TIME)); draughtsState = DraughtStateParser.parseDraughtsState(line); } catch (JSONException e) { formatter.printHelp("java -jar wtcl.jar", options); System.err.println( "JSON Exception on string " + line.getOptionValue(DraughtStateParser.OPT_BOARD)); throw e; } catch (Exception e) { formatter.printHelp("java -jar wtcl.jar", options); throw e; } execute(player, draughtsState, time, t0); }