/** * This method provides convenient way to parse command line arguments and validate them. * * @param args Command line arguments array * @throws IOException */ public void parseArgs(String[] args) throws IOException { CmdLineParser parser = new CmdLineParser(this); try { // parse the arguments. parser.parseArgument(args); // Validate arguments if (this.blockSize <= 32 || (!this.direction.equals("push") && !this.direction.equals("pull"))) { String errMsg = ""; if (this.blockSize <= 32) { errMsg += "Block size should be larger than 32 bytes.\n"; } if (!this.direction.equals("push") && !this.direction.equals("pull")) { errMsg += "Direction must be \"push\" or \"pull\""; } throw new CmdLineException(parser, errMsg); } } catch (CmdLineException e) { // print error message System.err.println(e.getMessage() + "\n"); System.err.println("java -jar syncclient.jar [options...] arguments..."); // print the list of available options parser.printUsage(System.err); System.err.println(); // print option sample System.err.println(" Example: java -jar syncclient.jar" + parser.printExample(ALL)); System.exit(-1); } }
/** * Simple test program. * * @param args */ public static void main(String[] args) { EclipseToEGS converter = new EclipseToEGS(); CmdLineParser parser = new CmdLineParser(converter); try { parser.parseArgument(args); converter.run(); } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); } }