List of usage examples for org.apache.commons.cli HelpFormatter HelpFormatter
HelpFormatter
From source file:fr.inria.atlanmod.kyanos.benchmarks.CdoQueryLoop.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);//from ww w . j av a2s . 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); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryLoop.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = JavaQueries.getUnusedMethodsLoop(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result (loops) contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } transaction.close(); session.close(); } finally { server.stop(); } } 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.CdoQueryOrphanNonPrimitiveTypes.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);//from w w w . java 2s.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); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryOrphanNonPrimitiveTypes.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { 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))); } transaction.close(); session.close(); } finally { server.stop(); } } 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.CdoQueryUnusedMethodsList.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/*from w ww . jav a2 s. c o 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); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryUnusedMethodsList.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { 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))); } transaction.close(); session.close(); } finally { server.stop(); } } 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:com.datazuul.iiif.presentation.api.ManifestGenerator.java
public static void main(String[] args) throws ParseException, JsonProcessingException, IOException, URISyntaxException { Options options = new Options(); options.addOption("d", true, "Absolute file path to the directory containing the image files."); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("d")) { String imageDirectoryPath = cmd.getOptionValue("d"); Path imageDirectory = Paths.get(imageDirectoryPath); final List<Path> files = new ArrayList<>(); try {//ww w . ja v a2 s. co m Files.walkFileTree(imageDirectory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory()) { // TODO there must be a more elegant solution for filtering jpeg files... if (file.getFileName().toString().endsWith("jpg")) { files.add(file); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } Collections.sort(files, new Comparator() { @Override public int compare(Object fileOne, Object fileTwo) { String filename1 = ((Path) fileOne).getFileName().toString(); String filename2 = ((Path) fileTwo).getFileName().toString(); try { // numerical sorting Integer number1 = Integer.parseInt(filename1.substring(0, filename1.lastIndexOf("."))); Integer number2 = Integer.parseInt(filename2.substring(0, filename2.lastIndexOf("."))); return number1.compareTo(number2); } catch (NumberFormatException nfe) { // alpha-numerical sorting return filename1.compareToIgnoreCase(filename2); } } }); generateManifest(imageDirectory.getFileName().toString(), files); } else { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ManifestGenerator", options); } }
From source file:com.redhat.akashche.wixgen.cli.Launcher.java
public static void main(String[] args) throws Exception { try {//from www .jav a 2 s. c om CommandLine cline = new GnuParser().parse(OPTIONS, args); if (cline.hasOption(VERSION_OPTION)) { out.println(VERSION); } else if (cline.hasOption(HELP_OPTION)) { throw new ParseException("Printing help page:"); } else if (1 == cline.getArgs().length && cline.hasOption(CONFIG_OPTION) && cline.hasOption(OUTPUT_OPTION) && !cline.hasOption(XSL_OPTION)) { WixConfig conf = parseConf(cline.getOptionValue(CONFIG_OPTION)); Wix wix = new DirectoryGenerator().createFromDir(new File(cline.getArgs()[0]), conf); Marshaller marshaller = createMarshaller(); writeXml(marshaller, wix, cline.getOptionValue(OUTPUT_OPTION), false); if (cline.hasOption(DIRECTORY_OPTION)) { Directory dir = findWixDirectory(wix); writeXml(marshaller, dir, cline.getOptionValue(DIRECTORY_OPTION), true); } if (cline.hasOption(FEATURE_OPTION)) { Feature feature = findWixFeature(wix); writeXml(marshaller, feature, cline.getOptionValue(FEATURE_OPTION), true); } } else if (1 == cline.getArgs().length && cline.hasOption(XSL_OPTION) && cline.hasOption(OUTPUT_OPTION)) { transformWithXsl(cline.getArgs()[0], cline.getOptionValue(XSL_OPTION), cline.getOptionValue(OUTPUT_OPTION)); } else { throw new ParseException("Incorrect arguments received!"); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); out.println(e.getMessage()); out.println(VERSION); formatter.printHelp("java -jar wixgen.jar input_dir -c config.json -o output.wxs", OPTIONS); } }
From source file:at.newmedialab.ldpath.template.LDTemplate.java
public static void main(String[] args) { Options options = buildOptions();/*from ww w . j a va2s .c om*/ CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); Level logLevel = Level.WARN; if (cmd.hasOption("loglevel")) { String logLevelName = cmd.getOptionValue("loglevel"); if ("DEBUG".equals(logLevelName.toUpperCase())) { logLevel = Level.DEBUG; } else if ("INFO".equals(logLevelName.toUpperCase())) { logLevel = Level.INFO; } else if ("WARN".equals(logLevelName.toUpperCase())) { logLevel = Level.WARN; } else if ("ERROR".equals(logLevelName.toUpperCase())) { logLevel = Level.ERROR; } else { log.error("unsupported log level: {}", logLevelName); } } if (logLevel != null) { for (String logname : new String[] { "at", "org", "net", "com" }) { ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory .getLogger(logname); logger.setLevel(logLevel); } } File template = null; if (cmd.hasOption("template")) { template = new File(cmd.getOptionValue("template")); } GenericSesameBackend backend; if (cmd.hasOption("store")) { backend = new LDPersistentBackend(new File(cmd.getOptionValue("store"))); } else { backend = new LDMemoryBackend(); } Resource context = null; if (cmd.hasOption("context")) { context = backend.getRepository().getValueFactory().createURI(cmd.getOptionValue("context")); } BufferedWriter out = null; if (cmd.hasOption("out")) { File of = new File(cmd.getOptionValue("out")); if (of.canWrite()) { out = new BufferedWriter(new FileWriter(of)); } else { log.error("cannot write to output file {}", of); System.exit(1); } } else { out = new BufferedWriter(new OutputStreamWriter(System.out)); } if (backend != null && context != null && template != null) { TemplateEngine<Value> engine = new TemplateEngine<Value>(backend); engine.setDirectoryForTemplateLoading(template.getParentFile()); engine.processFileTemplate(context, template.getName(), out); out.flush(); out.close(); } if (backend instanceof LDPersistentBackend) { ((LDPersistentBackend) backend).shutdown(); } } catch (ParseException e) { System.err.println("invalid arguments"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LDQuery", options, true); } catch (FileNotFoundException e) { System.err.println("file or program could not be found"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LDQuery", options, true); } catch (IOException e) { System.err.println("could not access file"); e.printStackTrace(System.err); } catch (TemplateException e) { System.err.println("error while processing template"); e.printStackTrace(System.err); } }
From source file:com.hpe.nv.samples.basic.BasicNVTest.java
public static void main(String[] args) { try {/* w w w. j a v a 2s . c o m*/ // program arguments Options options = new Options(); options.addOption("i", "server-ip", true, "[mandatory] NV Test Manager IP"); options.addOption("o", "server-port", true, "[mandatory] NV Test Manager port"); options.addOption("u", "username", true, "[mandatory] NV username"); options.addOption("w", "password", true, "[mandatory] NV password"); options.addOption("e", "ssl", true, "[optional] Pass true to use SSL. Default: false"); options.addOption("y", "proxy", true, "[optional] Proxy server host:port"); options.addOption("b", "browser", true, "[optional] The browser for which the Selenium WebDriver is built. Possible values: Chrome and Firefox. Default: Firefox"); options.addOption("d", "debug", true, "[optional] Pass true to view console debug messages during execution. Default: false"); options.addOption("h", "help", false, "[optional] Generates and prints help information"); // parse and validate the command line arguments CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { // print help if help argument is passed HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("BasicNVTest.java", options); return; } if (line.hasOption("server-ip")) { serverIp = line.getOptionValue("server-ip"); if (serverIp.equals("0.0.0.0")) { throw new Exception( "Please replace the server IP argument value (0.0.0.0) with your NV Test Manager IP"); } } else { throw new Exception("Missing argument -i/--server-ip <serverIp>"); } if (line.hasOption("server-port")) { serverPort = Integer.parseInt(line.getOptionValue("server-port")); } else { throw new Exception("Missing argument -o/--server-port <serverPort>"); } if (line.hasOption("username")) { username = line.getOptionValue("username"); } else { throw new Exception("Missing argument -u/--username <username>"); } if (line.hasOption("password")) { password = line.getOptionValue("password"); } else { throw new Exception("Missing argument -w/--password <password>"); } if (line.hasOption("ssl")) { ssl = Boolean.parseBoolean(line.getOptionValue("ssl")); } if (line.hasOption("proxy")) { proxySetting = line.getOptionValue("proxy"); } if (line.hasOption("browser")) { browser = line.getOptionValue("browser"); } else { browser = "Firefox"; } if (line.hasOption("debug")) { debug = Boolean.parseBoolean(line.getOptionValue("debug")); } String newLine = System.getProperty("line.separator"); String testDescription = "*** This sample demonstrates the use of the most basic NV methods. ***" + newLine + "*** ***" + newLine + "*** First, the sample creates a TestManager object and initializes it. ***" + newLine + "*** The sample starts an NV test over an emulated \"3G Busy\" network. ***" + newLine + "*** (\"3G Busy\" is one of NV's built-in network profiles. A network profile specifies the ***" + newLine + "*** network traffic behavior, including latency, packet loss, and incoming/outgoing bandwidth. ***" + newLine + "*** Network profiles are used to emulate traffic over real-world networks.) ***" + newLine + "*** ***" + newLine + "*** Next, the sample navigates to the home page in the HPE Network Virtualization website ***" + newLine + "*** using the Selenium WebDriver. ***" + newLine + "*** ***" + newLine + "*** Finally, the sample stops the NV test. ***" + newLine + "*** ***" + newLine + "*** You can view the actual steps of this sample in the BasicNVTest.java file. ***" + newLine; // print the sample's description System.out.println(testDescription); // start console spinner if (!debug) { spinner = new Thread(new Spinner()); spinner.start(); } // sample execution steps /***** Part 1 - Create a TestManager object and initialize it *****/ printPartDescription("\b------ Part 1 - Create a TestManager object and initialize it"); initTestManager(); printPartSeparator(); /***** Part 2 - Start the NV test with the "3G Busy" network scenario *****/ printPartDescription("------ Part 2 - Start the NV test with the \"3G Busy\" network scenario"); startTest(); testRunning = true; printPartSeparator(); /***** Part 3 - Navigate to the HPE Network Virtualization website *****/ printPartDescription("------ Part 3 - Navigate to the HPE Network Virtualization website"); buildSeleniumWebDriver(); seleniumNavigateToPage(); driverCloseAndQuit(); printPartSeparator(); /***** Part 4 - Stop the NV test *****/ printPartDescription("------ Part 4 - Stop the NV test"); stopTest(); testRunning = false; printPartSeparator(); doneCallback(); } catch (Exception e) { try { handleError(e.getMessage()); } catch (Exception e2) { System.out.println("Error occurred: " + e2.getMessage()); } } }
From source file:com.ovea.tajin.server.ContainerRunner.java
public static void main(String... args) throws Exception { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); if (line.hasOption("help") || !line.hasOption(Properties.CONTAINER.getName())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ContainerRunner.class.getSimpleName(), options); return;//from w w w . j a v a 2 s. c om } // Set default values // And override by system properties. This way, we can start ContainerRunner with specific options such as -DjettyConf=.. -DjettyEnv=... ContainerConfiguration settings = ContainerConfiguration.from(System.getProperties()); // Then parse command line for (Option option : line.getOptions()) { settings.set(Properties.from(option.getOpt()), line.getOptionValue(option.getOpt())); } Container container = settings.buildContainer(line.getOptionValue(Properties.CONTAINER.getName())); container.start(); }
From source file:fr.inria.atlanmod.kyanos.benchmarks.CdoQueryInvisibleMethodDeclarations.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/* ww w . ja 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); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryInvisibleMethodDeclarations.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = JavaQueries.getInvisibleMethodDeclarations(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))); } transaction.close(); session.close(); } finally { server.stop(); } } 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:com.dustindoloff.s3websitedeploy.Main.java
public static void main(final String[] args) { final Options options = buildOptions(); final CommandLineParser parser = new DefaultParser(); final CommandLine commandLine; try {/* w w w.j av a2s . c o m*/ commandLine = parser.parse(options, args); } catch (final ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp("s3WebsiteDeploy", options); System.exit(1); return; } final File websiteZip = new File(commandLine.getOptionValue(ARG_WEBSITE_ZIP)); final String s3Bucket = commandLine.getOptionValue(ARG_BUCKET); final String awsAccessKey = commandLine.getOptionValue(ARG_AWS_ACCESS_KEY); final String awsSecretKey = commandLine.getOptionValue(ARG_AWS_SECRET_KEY); final ZipFile zipFile = getAsValidZip(websiteZip); if (zipFile == null) { System.out.println("Invalid zip file passed in"); System.exit(2); return; } System.out.println("Running S3 Website Deploy"); final AmazonS3 s3Client = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey)); final Region bucketRegion = getBucketRegion(s3Client, s3Bucket); if (bucketRegion == null) { System.out.println("Unable to get the region for the bucket."); System.exit(3); return; } s3Client.setRegion(bucketRegion); if (!emptyBucket(s3Client, s3Bucket)) { System.out.println("Unable to upload to empty bucket."); System.exit(4); return; } if (!upload(s3Client, s3Bucket, zipFile)) { System.out.println("Unable to upload to S3."); System.exit(5); return; } System.out.println("Deployment Complete"); }