List of usage examples for org.apache.commons.cli Options Options
Options
From source file:com.yahoo.dba.tools.myperfserver.App.java
public static void main(String[] args) throws Exception { //-p --port 9090 //-r --webcontextroot webapps //-l --logpath logpath //-w --war webapp war file name CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption("j", "jettyHome", true, "Jetty home, if not set, check system property jetty.home, then default to current Dir"); options.addOption("p", "port", true, "http server port, default to 9090."); options.addOption("c", "webcontextroot", true, "web app url root context, defaul to /"); options.addOption("l", "logpath", true, "log path, default to current directory."); options.addOption("w", "warfile", true, "war file name, default to myperf.war."); options.addOption("k", "workdir", true, "work directory for jetty, default to current dir."); System.out.println(new Date() + " Usage: java -classpath ... com.yahoo.dba.tools.myperfserver.App -j jettyhome -p port -c webcontextroot -k workingDir -l logpath -w war_file"); App myServer = new App(); try {/* ww w.ja v a2 s . c o m*/ // parse the command line arguments CommandLine line = parser.parse(options, args); // validate that block-size has been set if (line.hasOption("p")) { try { myServer.setPort(Short.parseShort(line.getOptionValue("p"))); } catch (Exception ex) { } } if (line.hasOption("c")) { String val = line.getOptionValue("c"); if (val != null && !val.isEmpty()) myServer.setContextPath(val); } if (line.hasOption("l")) { String val = line.getOptionValue("l"); if (val != null && !val.isEmpty()) myServer.setLogPath(val); } if (line.hasOption("w")) { String val = line.getOptionValue("w"); if (val != null && !val.isEmpty()) myServer.setWarFile(val); } if (line.hasOption("k")) { String val = line.getOptionValue("k"); myServer.setWorkDir(val); } if (line.hasOption("j")) { String val = line.getOptionValue("j"); if (val != null && !val.isEmpty()) myServer.setJettyHome(val); } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); } System.setProperty("logPath", myServer.getLogPath()); PID_FILE = myServer.getWarFile().substring(0, myServer.getWarFile().indexOf('.')) + ".pid"; int historyPid = getHistoryPid(); if (historyPid >= 0) { System.out.println(new Date() + " *************************** WARNING *********************"); System.out .println(PID_FILE + " exists. Possibly another instance is still running. PID = " + historyPid); System.out.println(new Date() + " *************************** WARNING *********************"); } if (myServer.startServer()) { pid = getPid(); writePid(); myServer.waitForInterrupt(); removePid(); } else System.out.println("Server not started."); }
From source file:com.linkedin.databus2.client.util.DbusClientClusterUtil.java
/** * @param args/*from w w w. j a v a2 s.c om*/ * DbusClientClusterUtil -s <serverList> -n <namespace> -g <group> -d <dir> members * leader * keys * readSCN <key> * writeSCN <key> SCN [OFFSET] * remove <key> * readLastTS * writeLastTS TIMESTAMP */ public static void main(String[] args) { try { GnuParser cmdLineParser = new GnuParser(); Options options = new Options(); options.addOption("n", true, "Zookeeper namespace [/DatabusClient") .addOption("g", true, "Groupname [default-group-name] ") .addOption("d", true, "Shared directory name [shareddata] ") .addOption("s", true, "Zookeeper server list [localhost:2181] ").addOption("h", false, "help"); CommandLine cmdLineArgs = cmdLineParser.parse(options, args, false); if (cmdLineArgs.hasOption('h')) { usage(); System.exit(0); } String namespace = cmdLineArgs.getOptionValue('n'); if (namespace == null || namespace.isEmpty()) { namespace = "/DatabusClient"; } String groupname = cmdLineArgs.getOptionValue('g'); if (groupname == null || groupname.isEmpty()) { groupname = "default-group-name"; } String sharedDir = cmdLineArgs.getOptionValue('d'); if (sharedDir == null || sharedDir.isEmpty()) { sharedDir = "shareddata"; } String serverList = cmdLineArgs.getOptionValue('s'); if (serverList == null || serverList.isEmpty()) { serverList = "localhost:2181"; } String[] fns = cmdLineArgs.getArgs(); if (fns.length < 1) { usage(); System.exit(1); } String function = fns[0]; String arg1 = (fns.length > 1) ? fns[1] : null; String arg2 = (fns.length > 2) ? fns[2] : null; try { String memberName = "cmd-line-tool"; DatabusClientNode clusterNode = new DatabusClientNode(new DatabusClientNode.StaticConfig(true, serverList, 2000, 5000, namespace, groupname, memberName, false, sharedDir)); DatabusClientGroupMember member = clusterNode.getMember(namespace, groupname, memberName); if (member == null || !member.joinWithoutLeadershipDuties()) { System.err.println("Initialization failed for: " + member); System.exit(1); } if (function.equals("members")) { List<String> mlist = member.getMembers(); for (String m : mlist) { System.out.println(m); } } else if (function.equals("leader")) { String leader = member.getLeader(); System.out.println(leader); } else if (function.equals("keys")) { List<String> keyList = member.getSharedKeys(); if (keyList != null) { for (String m : keyList) { System.out.println(m); } } } else if (function.equals("readSCN")) { List<String> keyList; if (arg1 == null) { keyList = member.getSharedKeys(); } else { keyList = new ArrayList<String>(); keyList.add(arg1); } if (keyList != null) { for (String k : keyList) { if (!k.equals(DatabusClientDSCUpdater.DSCKEY)) { Checkpoint cp = (Checkpoint) member.readSharedData(k); if (cp != null) { System.out.println(k + " " + cp.getWindowScn() + " " + cp.getWindowOffset()); } else { System.err.println(k + " null null"); } } } } } else if (function.equals("writeSCN")) { if (arg1 != null && arg2 != null) { Checkpoint cp = new Checkpoint(); cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION); cp.setWindowScn(Long.parseLong(arg2)); if (fns.length > 3) { cp.setWindowOffset(Integer.parseInt(fns[3])); } else { cp.setWindowOffset(-1); } if (member.writeSharedData(arg1, cp)) { System.out.println(arg1 + " " + cp.getWindowScn() + " " + cp.getWindowOffset()); } else { System.err.println("Write failed! " + member + " couldn't write key=" + arg1); System.exit(1); } } else { usage(); System.exit(1); } } else if (function.equals("readLastTs")) { Long timeInMs = (Long) member.readSharedData(DatabusClientDSCUpdater.DSCKEY); if (timeInMs != null) { System.out.println(DatabusClientDSCUpdater.DSCKEY + " " + timeInMs.longValue()); } else { System.err.println(DatabusClientDSCUpdater.DSCKEY + " null"); } } else if (function.equals("writeLastTs")) { if (arg1 != null) { Long ts = Long.parseLong(arg1); if (member.writeSharedData(DatabusClientDSCUpdater.DSCKEY, ts)) { System.out.println(DatabusClientDSCUpdater.DSCKEY + " " + ts); } else { System.err.println("Write failed! " + member + " couldn't write key=" + DatabusClientDSCUpdater.DSCKEY); System.exit(1); } } else { usage(); System.exit(1); } } else if (function.equals("remove")) { if (!member.removeSharedData(arg1)) { System.err.println("Remove failed! " + arg1); System.exit(1); } } else if (function.equals("create")) { if (!member.createPaths()) { System.err.println("Create path failed!"); System.exit(1); } } else { usage(); System.exit(1); } } catch (InvalidConfigException e) { e.printStackTrace(); usage(); System.exit(1); } } catch (ParseException e) { usage(); System.exit(1); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryOrphanNonPrimitiveTypes.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);// ww w . ja va 2 s . co m inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryOrphanNonPrimitiveTypes.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<Type> list = JavaQueries.getOrphanNonPrimitivesTypes(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } if (resource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource); } else { resource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryUnusedMethodsList.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);/*from www. j a v a 2 s.com*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryUnusedMethodsList.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = JavaQueries.getUnusedMethodsList(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } if (resource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource); } else { resource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:dyco4j.instrumentation.internals.CLI.java
public static void main(final String[] args) throws IOException { final Options _options = new Options(); _options.addOption(Option.builder().longOpt(IN_FOLDER_OPTION).required().hasArg(true) .desc("Folders containing the classes to be instrumented.").build()); _options.addOption(Option.builder().longOpt(OUT_FOLDER_OPTION).required().hasArg(true) .desc("Folder containing the classes (as descendants) with instrumentation.").build()); _options.addOption(Option.builder().longOpt(CLASSPATH_CONFIG_OPTION).hasArg(true) .desc("File containing class path (1 entry per line) used by classes to be instrumented.").build()); final String _msg = MessageFormat.format("Regex identifying the methods to be instrumented. Default: {0}.", METHOD_NAME_REGEX);//from www .ja v a 2 s . c om _options.addOption(Option.builder().longOpt(METHOD_NAME_REGEX_OPTION).hasArg(true).desc(_msg).build()); _options.addOption(Option.builder().longOpt(TRACE_ARRAY_ACCESS_OPTION).hasArg(false) .desc("Instrument to trace array access.").build()); _options.addOption(Option.builder().longOpt(TRACE_FIELD_ACCESS_OPTION).hasArg(false) .desc("Instrument to trace field access.").build()); _options.addOption(Option.builder().longOpt(TRACE_METHOD_ARGUMENTS_OPTION).hasArg(false) .desc("Instrument to trace method arguments.").build()); _options.addOption(Option.builder().longOpt(TRACE_METHOD_CALL_OPTION).hasArg(false) .desc("Instrument to trace method calls (compile-time signatures).").build()); _options.addOption(Option.builder().longOpt(TRACE_METHOD_RETURN_VALUE_OPTION).hasArg(false) .desc("Instrument to trace method return values.").build()); try { final CommandLine _cmdLine = new DefaultParser().parse(_options, args); extendClassPath(_cmdLine); processCommandLine(_cmdLine); } catch (final ParseException _ex1) { new HelpFormatter().printHelp(CLI.class.getName(), _options); } }
From source file:com.ctriposs.rest4j.tools.idlcheck.Rest4JResourceModelCompatibilityChecker.java
@SuppressWarnings({ "static" }) public static void main(String[] args) { final Options options = new Options(); options.addOption("h", "help", false, "Print help"); options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg() .withDescription("Compatibility level " + listCompatLevelOptions()).create('c')); final String cmdLineSyntax = Rest4JResourceModelCompatibilityChecker.class.getCanonicalName() + " [pairs of <prevRestspecPath currRestspecPath>]"; final CommandLineParser parser = new PosixParser(); final CommandLine cmd; try {//from w ww.jav a 2s . c o m cmd = parser.parse(options, args); } catch (ParseException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); return; // to suppress IDE warning } final String[] targets = cmd.getArgs(); if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); } final String compatValue; if (cmd.hasOption('c')) { compatValue = cmd.getOptionValue('c'); } else { compatValue = CompatibilityLevel.DEFAULT.name(); } final CompatibilityLevel compat; try { compat = CompatibilityLevel.valueOf(compatValue.toUpperCase()); } catch (IllegalArgumentException e) { new HelpFormatter().printHelp(cmdLineSyntax, options, true); System.exit(1); return; } final StringBuilder allSummaries = new StringBuilder(); boolean result = true; for (int i = 1; i < targets.length; i += 2) { final Rest4JResourceModelCompatibilityChecker checker = new Rest4JResourceModelCompatibilityChecker(); checker.setResolverPath(System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH)); String prevTarget = targets[i - 1]; String currTarget = targets[i]; result &= checker.check(prevTarget, currTarget, compat); allSummaries.append(checker.getInfoMap().createSummary(prevTarget, currTarget)); } if (compat != CompatibilityLevel.OFF && allSummaries.length() > 0) { System.out.println(allSummaries); } System.exit(result ? 0 : 1); }
From source file:com.spotify.cassandra.opstools.CountTombstones.java
/** * Counts the number of tombstones, per row, in a given SSTable * * Assumes RandomPartitioner, standard columns and UTF8 encoded row keys * * Does not require a cassandra.yaml file or system tables. * * @param args command lines arguments//from w w w .j a v a 2 s.c o m * * @throws java.io.IOException on failure to open/read/write files or output streams */ public static void main(String[] args) throws IOException, ParseException { String usage = String.format("Usage: %s [-l] <sstable> [<sstable> ...]%n", CountTombstones.class.getName()); final Options options = new Options(); options.addOption("l", "legend", false, "Include column name explanation"); options.addOption("p", "partitioner", true, "The partitioner used by database"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.getArgs().length < 1) { System.err.println("You must supply at least one sstable"); System.err.println(usage); System.exit(1); } // Fake DatabaseDescriptor settings so we don't have to load cassandra.yaml etc Config.setClientMode(true); String partitionerName = String.format("org.apache.cassandra.dht.%s", options.hasOption("p") ? options.getOption("p") : "RandomPartitioner"); try { Class<?> clazz = Class.forName(partitionerName); IPartitioner partitioner = (IPartitioner) clazz.newInstance(); DatabaseDescriptor.setPartitioner(partitioner); } catch (Exception e) { throw new RuntimeException("Can't instantiate partitioner " + partitionerName); } PrintStream out = System.out; for (String arg : cmd.getArgs()) { String ssTableFileName = new File(arg).getAbsolutePath(); Descriptor descriptor = Descriptor.fromFilename(ssTableFileName); run(descriptor, cmd, out); } System.exit(0); }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryThrownExceptionsPerPackage.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);/*from w w w. j a v a 2s . c om*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryThrownExceptionsPerPackage.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); HashMap<String, EList<TypeAccess>> list = JavaQueries.getThrownExceptionsPerPackage(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } if (resource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource); } else { resource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:io.github.azige.whitespace.Cli.java
public static void main(String[] args) { Options options = new Options().addOption("h", "help", false, "??") .addOptionGroup(new OptionGroup() .addOption(new Option("p", "????????")) .addOption(new Option("c", "?????"))) .addOption(null, "szm", false, "????") .addOption("e", "encoding", true, "??" + DEFAULT_ENCODING); try {//from www.j av a2 s.c o m CommandLineParser parser = new BasicParser(); CommandLine cl = parser.parse(options, args); if (cl.hasOption('h')) { printHelp(System.out, options); return; } if (cl.hasOption('e')) { encoding = Charset.forName(cl.getOptionValue('e')); } else { encoding = Charset.forName(DEFAULT_ENCODING); } if (cl.hasOption("szm")) { useSzm = true; } String[] fileArgs = cl.getArgs(); if (fileArgs.length != 1) { printHelp(System.err, options); return; } try (InputStream input = Files.newInputStream(Paths.get(fileArgs[0]))) { if (cl.hasOption('p')) { printPseudoCode(input); } else if (cl.hasOption('c')) { compile(input, fileArgs[0]); } else { execute(input, fileArgs[0]); } } } catch (ParseException ex) { ex.printStackTrace(); printHelp(System.err, options); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.google.testing.pogen.PageObjectGenerator.java
@SuppressWarnings("static-access") public static void main(String[] args) { if (args.length == 0) { printUsage(System.out);/*from w ww. j av a 2 s . co m*/ return; } String commandName = args[0]; // @formatter:off Options options = new Options() .addOption(OptionBuilder.withDescription( "Attribute name to be assigned in tagas containing template variables (default is 'id').") .hasArg().withLongOpt("attr").create('a')) .addOption(OptionBuilder.withDescription("Print help for this command.").withLongOpt("help") .create('h')) .addOption(OptionBuilder.withDescription("Print processed files verbosely.").withLongOpt("verbose") .create('v')); // @formatter:on String helpMessage = null; if (commandName.equals(GENERATE_COMMAND)) { // @formatter:off options.addOption(OptionBuilder.withDescription("Package name of generating skeleton test code.") .hasArg().isRequired().withLongOpt("package").create('p')) .addOption(OptionBuilder.withDescription("Output directory of generating skeleton test code.") .hasArg().isRequired().withLongOpt("out").create('o')) .addOption(OptionBuilder.withDescription( "Root input directory of html template files for analyzing the suffixes of the package name.") .hasArg().isRequired().withLongOpt("in").create('i')) .addOption(OptionBuilder.withDescription("Regex for finding html template files.").hasArg() .withLongOpt("regex").create('e')) .addOption(OptionBuilder.withDescription("Option for finding html template files recursively.") .withLongOpt("recursive").create('r')); // @formatter:on helpMessage = "java PageObjectGenerator generate -o <test_out_dir> -p <package_name> -i <root_directory> " + " [OPTIONS] <template_file1> <template_file2> ...\n" + "e.g. java PageObjectGenerator generate -a class -o PageObjectGeneratorTest/src/test/java/com/google/testing/pogen/pages" + " -i PageObjectGeneratorTest/src/main/resources -p com.google.testing.pogen.pages -e (.*)\\.html -v"; } else if (commandName.equals(MEASURE_COMMAND)) { helpMessage = "java PageObjectGenerator measure [OPTIONS] <template_file1> <template_file2> ..."; } else if (commandName.equals(LIST_COMMAND)) { helpMessage = "java PageObjectGenerator list <template_file1> <template_file2> ..."; } else { System.err.format("'%s' is not a PageObjectGenerator command.", commandName); printUsage(System.err); System.exit(-1); } BasicParser cmdParser = new BasicParser(); HelpFormatter f = new HelpFormatter(); try { CommandLine cl = cmdParser.parse(options, Arrays.copyOfRange(args, 1, args.length)); if (cl.hasOption('h')) { f.printHelp(helpMessage, options); return; } Command command = null; String[] templatePaths = cl.getArgs(); String attributeName = cl.getOptionValue('a'); attributeName = attributeName != null ? attributeName : "id"; if (commandName.equals(GENERATE_COMMAND)) { String rootDirectoryPath = cl.getOptionValue('i'); String templateFilePattern = cl.getOptionValue('e'); boolean isRecusive = cl.hasOption('r'); command = new GenerateCommand(templatePaths, cl.getOptionValue('o'), cl.getOptionValue('p'), attributeName, cl.hasOption('v'), rootDirectoryPath, templateFilePattern, isRecusive); } else if (commandName.equals(MEASURE_COMMAND)) { command = new MeasureCommand(templatePaths, attributeName, cl.hasOption('v')); } else if (commandName.equals(LIST_COMMAND)) { command = new ListCommand(templatePaths, attributeName); } try { command.execute(); return; } catch (FileProcessException e) { System.err.println(e.getMessage()); } catch (IOException e) { System.err.println("Errors occur in processing files."); System.err.println(e.getMessage()); } } catch (ParseException e) { System.err.println("Errors occur in parsing the command arguments."); System.err.println(e.getMessage()); f.printHelp(helpMessage, options); } System.exit(-1); }