List of usage examples for org.apache.commons.cli ParseException getMessage
public String getMessage()
From source file:io.github.azige.mages.Cli.java
public static void main(String[] args) { Options options = new Options().addOption("h", "help", false, "print this message") .addOption(Option.builder("r").hasArg().argName("bundle").desc("set the ResourceBundle").build()) .addOption(Option.builder("l").hasArg().argName("locale").desc("set the locale").build()) .addOption(Option.builder("t").hasArg().argName("template").desc("set the template").build()) .addOption(Option.builder("p").hasArg().argName("plugin dir") .desc("set the directory to load plugins").build()) .addOption(Option.builder("f").desc("force override existed file").build()); try {//from ww w . jav a 2s . c o m CommandLineParser parser = new DefaultParser(); CommandLine cl = parser.parse(options, args); if (cl.hasOption('h')) { printHelp(System.out, options); return; } MagesSiteGenerator msg = new MagesSiteGenerator(new File("."), new File(".")); String[] fileArgs = cl.getArgs(); if (fileArgs.length < 1) { msg.addTask("."); } else { for (String path : fileArgs) { msg.addTask(path); } } if (cl.hasOption("t")) { msg.setTemplate(new File(cl.getOptionValue("t"))); } if (cl.hasOption("r")) { msg.setResource(new File(cl.getOptionValue("r"))); } else { File resource = new File("Resource.properties"); if (resource.exists()) { msg.setResource(resource); } } if (cl.hasOption("p")) { msg.setPluginDir(new File(cl.getOptionValue("p"))); } if (cl.hasOption("f")) { msg.setForce(true); } msg.start(); } catch (ParseException ex) { System.err.println(ex.getMessage()); printHelp(System.err, options); } }
From source file:cc.wikitools.lucene.FindWikipediaArticleId.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(/* w ww.j ava 2s. com*/ OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(TITLE_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(FindWikipediaArticleId.class.getName(), options); System.exit(-1); } File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION)); if (!indexLocation.exists()) { System.err.println("Error: " + indexLocation + " does not exist!"); System.exit(-1); } String title = cmdline.getOptionValue(TITLE_OPTION); PrintStream out = new PrintStream(System.out, true, "UTF-8"); WikipediaSearcher searcher = new WikipediaSearcher(indexLocation); int id = searcher.getArticleId(title); out.println(title + ": id = " + id); searcher.close(); out.close(); }
From source file:main.Main.java
/** * The public main function./*from w ww.j a va2 s .c o m*/ * @param args */ public static void main(String[] args) { System.out.println("Starting"); Options options = new Options(); Option solutionOption = new Option("s", "solution", true, "This will be the " + "solution of the cross word game. (aka. This will be the first" + " vertical word on the canvas.)"); // solutionOption.setRequired(true); Option numOfBatchOption = new Option("n", "numOfBatch", true, ""); Option verboseOption = new Option("v", "verbose", false, "Print some debug information during running."); Option veryVerboseOption = new Option("vv", "very-verbose", false, "Print more debug information."); options.addOption(solutionOption); options.addOption(numOfBatchOption); options.addOption(verboseOption); options.addOption(veryVerboseOption); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("utility-name", options); System.exit(1); return; } System.out.println(cmd.getArgList()); int debugLevel = 0; if (cmd.hasOption("verbose")) { debugLevel = 1; } if (cmd.hasOption("very-verbose")) { debugLevel = 2; } String solution = cmd.getOptionValue("solution"); if (null == solution) { startGui(); } else { int numOfBatch = Integer.valueOf(cmd.getOptionValue("numOfBatch", "200")); System.out.println(solution); Generator gen = new Generator(solution, debugLevel); // <---- EDIT THIS LINE FOR DIFFERENT SOLUTIONS. long startTime = System.currentTimeMillis(); gen.generate(numOfBatch); long estimatedTime = System.currentTimeMillis() - startTime; System.out.print("estimatedTime: " + estimatedTime + "ms"); } }
From source file:com.act.biointerpretation.l2expansion.L2PredictionCorpusOperations.java
public static void main(String[] args) throws IOException { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//ww w . j a v a2 s. c om } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { LOGGER.error("Argument parsing failed: %s", e.getMessage()); HELP_FORMATTER.printHelp(L2PredictionCorpusOperations.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(L2PredictionCorpusOperations.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption(OPTION_WRITE_PRODUCTS_AS_LIST_OF_INCHIS)) { L2PredictionCorpus corpus = L2PredictionCorpus.readPredictionsFromJsonFile( new File(cl.getOptionValue(OPTION_WRITE_PRODUCTS_AS_LIST_OF_INCHIS))); corpus.writePredictionsAsInchiList( new File(cl.getOptionValue(OPTION_WRITE_PRODUCTS_AS_LIST_OF_INCHIS))); } }
From source file:cc.twittertools.index.ExtractTweetidsFromIndex.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(//from w ww . j a v a 2s . c om OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractTweetidsFromIndex.class.getName(), options); System.exit(-1); } File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION)); if (!indexLocation.exists()) { System.err.println("Error: " + indexLocation + " does not exist!"); System.exit(-1); } IndexReader reader = DirectoryReader.open(FSDirectory.open(indexLocation)); PrintStream out = new PrintStream(System.out, true, "UTF-8"); for (int i = 0; i < reader.maxDoc(); i++) { Document doc = reader.document(i); out.println(doc.getField(StatusField.ID.name).stringValue() + "\t" + doc.getField(StatusField.SCREEN_NAME.name).stringValue()); } out.close(); reader.close(); }
From source file:net.sourceforge.jencrypt.jencrypt.java
/** * Handle command-line interface: parse arguments and cipher files * with a password derived key./* w w w . ja v a 2 s .c o m*/ */ public static void main(String[] args) throws Exception { //args = new String[]{"-e","d:\\tmp\\test","d:\\o"+System.nanoTime(),"-ini","d:\\jencrypt-1.3.3\\jencrypt.ini","-p","pass"}; try { CommandLineHelper commandline = new CommandLineHelper(args); if (commandline.isValid()) { // Read and check the configuration file ConfigHelper config = new ConfigHelper(commandline.getConfigFileString()); String logFile = null; if (config.logFileIsEnabled()) { logFile = config.getLogFile(); } logger = new JEncryptLog(logFile, "net.sourceforge.jencrypt", null); // Initialize FileEncrypter with ConfigHelper, CommandLineHelper and JEncryptLog objects FileEncrypter jEncrypter = new FileEncrypter(config, commandline, logger); // Start cipher process jEncrypter.cipherFileOrFolder(); } else { commandline.printHelp(); } } catch (ParseException e) { System.err.println(e.getMessage()); systemExit(ExitCode.INVALID_ARGUMENTS); } catch (Exception e) { if (logger != null) logger.severe(e.getMessage(), true); else System.err.println(e.getMessage()); systemExit(ExitCode.EXCEPTION_OCCURRED); } systemExit(ExitCode.SUCCESS); }
From source file:de.fischer.thotti.core.runner.TargetURLGenerator.java
public static final void main(String[] args) { String accessKey = null;/*from ww w. ja v a 2 s . c o m*/ String secretKey = null; Options options = createCommandLineOption(); CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (!line.hasOption("ak")) { throw new ParseException("AWS Accress Key is missing."); } if (!line.hasOption("sk")) { throw new ParseException("AWS Secret Key is missing."); } accessKey = line.getOptionValue("ak"); secretKey = line.getOptionValue("sk"); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); System.exit(1); } TargetURLGenerator generator = new TargetURLGenerator(); generator.setAccessKey(accessKey); generator.setSecretKey(secretKey); generator.run(); }
From source file:com.bachelor.boulmier.workmaster.WorkMaster.java
public static void main(String[] args) throws IOException, InterruptedException { defineOptions();//from ww w. j av a2 s. com CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(options, args); if (cmd.hasOption(MasterConfig.CMD.CLILONGOPT)) { cliEnabled = true; } if (cmd.hasOption(MasterConfig.CMD.DEBUGLONGOPT)) { debug = true; } if (cmd.hasOption(MasterConfig.CMD.MAXVMLONGOPT)) { maxVM = Integer.valueOf(cmd.getOptionValue(MasterConfig.CMD.MAXVMLONGOPT)); } if (cmd.hasOption(MasterConfig.CMD.VERBOSELONGOPT)) { verbose = true; } if (cmd.hasOption(MasterConfig.CMD.REMOTEWSLONGOPT)) { webServer = cmd.getOptionValue(MasterConfig.CMD.REMOTEWSLONGOPT); if (!MasterConfig.DEFAULT.IP_PORT_PATTERN.matcher(webServer).matches()) { throw new ParseException("Given IP:PORT does not match pattern"); } } if (cmd.hasOption(MasterConfig.CMD.HELPLONGOPT)) { printHelp(); } logger = LoggerFactory.getLogger(); QueuingService.get() .send(RequestBuilder.builder().withExecutableName(ExecutableName.CAT) .with(RequestProperty.CLIENT_EMAIL, "anthony.boulmier.cfpt@gmail.com") .with(RequestProperty.JOB_IDENTIFIER, UUID.randomUUID().toString()) .with(RequestProperty.ARGS, "JobExecutor.log").create()); Thread.sleep(3000); } catch (ParseException pe) { logger.error(pe.getMessage()); printHelp(); } }
From source file:edu.usc.pgroup.floe.client.commands.SwitchAlternate.java
/** * Entry point for Scale command.//from www .ja v a 2 s .c o m * @param args command line arguments sent by the floe.py script. */ public static void main(final String[] args) { Options options = new Options(); Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired() .withDescription("Application Name").create("app"); Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired() .withDescription("Pellet Name").create("pellet"); Option alternateOption = OptionBuilder.withArgName("alternate").hasArg().withType(new String()) .withDescription("The new alternate to switch to.").create("alternate"); options.addOption(appOption); options.addOption(pelletNameOption); options.addOption(alternateOption); CommandLineParser parser = new BasicParser(); CommandLine line; try { line = parser.parse(options, args); } catch (ParseException e) { LOGGER.error("Invalid command: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("scale options", options); return; } String app = line.getOptionValue("app"); String pellet = line.getOptionValue("pellet"); String alternate = line.getOptionValue("alternate"); LOGGER.info("Application: {}", app); LOGGER.info("Pellet: {}", pellet); LOGGER.info("alternate: {}", alternate); try { FloeClient.getInstance().getClient().switchAlternate(app, pellet, alternate); } catch (TException e) { LOGGER.error("Error while connecting to the coordinator: {}", e); } }
From source file:com.redhat.akashche.keystoregen.Launcher.java
public static void main(String[] args) throws Exception { try {//w ww . j a v a 2 s .c o m 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 (0 == cline.getArgs().length && cline.hasOption(CONFIG_OPTION) && cline.hasOption(OUTPUT_OPTION)) { KeystoreConfig conf = parseConf(cline.getOptionValue(CONFIG_OPTION)); KeyStore ks = new KeystoreGenerator().generate(conf); writeKeystore(conf, ks, 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 keystoregen.jar -c config.json -o output.p12", OPTIONS); } }