List of usage examples for org.apache.commons.cli Options addOption
public Options addOption(Option opt)
From source file:com.ibm.crail.tools.CrailFsck.java
public static void main(String[] args) throws Exception { String type = ""; String filename = "/tmp.dat"; long offset = 0; long length = 1; boolean randomize = false; int storageClass = 0; int locationClass = 0; Option typeOption = Option.builder("t").desc( "type of experiment [getLocations|directoryDump|namenodeDump|blockStatistics|ping|createDirectory]") .hasArg().build();/*from ww w .ja va 2s. c om*/ Option fileOption = Option.builder("f").desc("filename").hasArg().build(); Option offsetOption = Option.builder("y").desc("offset into the file").hasArg().build(); Option lengthOption = Option.builder("l").desc("length of the file [bytes]").hasArg().build(); Option storageOption = Option.builder("c").desc("storageClass for file [1..n]").hasArg().build(); Option locationOption = Option.builder("p").desc("locationClass for file [1..n]").hasArg().build(); Options options = new Options(); options.addOption(typeOption); options.addOption(fileOption); options.addOption(offsetOption); options.addOption(lengthOption); options.addOption(storageOption); options.addOption(locationOption); CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length)); if (line.hasOption(typeOption.getOpt())) { type = line.getOptionValue(typeOption.getOpt()); } if (line.hasOption(fileOption.getOpt())) { filename = line.getOptionValue(fileOption.getOpt()); } if (line.hasOption(offsetOption.getOpt())) { offset = Long.parseLong(line.getOptionValue(offsetOption.getOpt())); } if (line.hasOption(lengthOption.getOpt())) { length = Long.parseLong(line.getOptionValue(lengthOption.getOpt())); } if (line.hasOption(storageOption.getOpt())) { storageClass = Integer.parseInt(line.getOptionValue(storageOption.getOpt())); } if (line.hasOption(locationOption.getOpt())) { locationClass = Integer.parseInt(line.getOptionValue(locationOption.getOpt())); } CrailFsck fsck = new CrailFsck(); if (type.equals("getLocations")) { fsck.getLocations(filename, offset, length); } else if (type.equals("directoryDump")) { fsck.directoryDump(filename, randomize); } else if (type.equals("namenodeDump")) { fsck.namenodeDump(); } else if (type.equals("blockStatistics")) { fsck.blockStatistics(filename); } else if (type.equals("ping")) { fsck.ping(); } else if (type.equals("createDirectory")) { fsck.createDirectory(filename, storageClass, locationClass); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("crail fsck", options); System.exit(-1); } }
From source file:com.act.biointerpretation.desalting.ChemicalDesalter.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build()); }//from www . j a va 2 s . c o m CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(ReactionDesalter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } ChemicalDesalter runner = new ChemicalDesalter(); String outAnalysis = cl.getOptionValue(OPTION_OUTPUT_PREFIX); if (cl.hasOption(OPTION_INCHI_INPUT_LIST)) { File inputFile = new File(cl.getOptionValue(OPTION_INCHI_INPUT_LIST)); if (!inputFile.exists()) { System.err.format("Cannot find input file at %s\n", inputFile.getAbsolutePath()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } runner.exampleChemicalsList(outAnalysis, inputFile); } }
From source file:com.quanticate.opensource.pdftkbox.PDFtkBox.java
public static void main(String[] args) throws Exception { // For printing help Options optsHelp = new Options(); optsHelp.addOption(Option.builder("help").required().desc("print this message").build()); // Normal-style import/export Options optsNormal = new Options(); OptionGroup normal = new OptionGroup(); Option optExport = Option.builder("export").required().hasArg().desc("export bookmarks from pdf") .argName("source-pdf").build(); normal.addOption(optExport);//from w w w . jav a2 s . c o m Option optImport = Option.builder("import").required().hasArg().desc("import bookmarks into pdf") .argName("source-pdf").build(); normal.addOption(optImport); optsNormal.addOptionGroup(normal); Option optBookmarks = Option.builder("bookmarks").hasArg().desc("bookmarks definition file") .argName("bookmarks").build(); optsNormal.addOption(optBookmarks); Option optOutput = Option.builder("output").hasArg().desc("output to new pdf").argName("pdf").build(); optsNormal.addOption(optOutput); // PDFtk style options Options optsPDFtk = new Options(); OptionGroup pdftk = new OptionGroup(); Option optDumpData = Option.builder("dump_data").required().desc("dump bookmarks from pdf").build(); pdftk.addOption(optDumpData); Option optUpdateInfo = Option.builder("update_info").required().hasArg().desc("update bookmarks in pdf") .argName("bookmarks").build(); pdftk.addOption(optUpdateInfo); optsPDFtk.addOptionGroup(pdftk); optsPDFtk.addOption(optOutput); // What are we doing? CommandLineParser parser = new DefaultParser(); // Did they want help? try { parser.parse(optsHelp, args); // If we get here, they asked for help doPrintHelp(optsHelp, optsNormal, optsPDFtk); return; } catch (ParseException pe) { } // Normal-style import/export? try { CommandLine line = parser.parse(optsNormal, args); // Export if (line.hasOption(optExport.getOpt())) { doExport(line.getOptionValue(optExport.getOpt()), line.getOptionValue(optBookmarks.getOpt()), line.getArgs()); return; } // Import with explicit output filename if (line.hasOption(optImport.getOpt()) && line.hasOption(optOutput.getOpt())) { doImport(line.getOptionValue(optImport.getOpt()), line.getOptionValue(optBookmarks.getOpt()), line.getOptionValue(optOutput.getOpt()), null); return; } // Import with implicit output filename if (line.hasOption(optImport.getOpt()) && line.getArgs().length > 0) { doImport(line.getOptionValue(optImport.getOpt()), line.getOptionValue(optBookmarks.getOpt()), null, line.getArgs()); return; } } catch (ParseException pe) { } // PDFtk-style if (args.length > 1) { // Nobble things for PDFtk-style options and Commons CLI for (int i = 1; i < args.length; i++) { for (Option opt : optsPDFtk.getOptions()) { if (args[i].equals(opt.getOpt())) { args[i] = "-" + args[i]; } } } try { // Input file comes first, then arguments String input = args[0]; String[] pargs = new String[args.length - 1]; System.arraycopy(args, 1, pargs, 0, pargs.length); // Parse what's left and check CommandLine line = parser.parse(optsPDFtk, pargs); if (line.hasOption(optDumpData.getOpt())) { doExport(input, line.getOptionValue(optOutput.getOpt()), line.getArgs()); return; } if (line.hasOption(optUpdateInfo.getOpt())) { doImport(input, line.getOptionValue(optUpdateInfo.getOpt()), line.getOptionValue(optOutput.getOpt()), line.getArgs()); return; } } catch (ParseException pe) { } } // If in doubt, print help doPrintHelp(optsHelp, optsNormal, optsPDFtk); }
From source file:com.act.analysis.similarity.ROBinning.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build()); }/*ww w.jav a 2s . c om*/ CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(ROBinning.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(ROBinning.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } String dbName = cl.getOptionValue(OPTION_DB); // We read and write to the same database NoSQLAPI api = new NoSQLAPI(dbName, dbName); ErosCorpus erosCorpus = new ErosCorpus(); erosCorpus.loadValidationCorpus(); ROBinning roBinning = new ROBinning(erosCorpus, api); roBinning.init(); roBinning.processChemicals(); }
From source file:com.act.biointerpretation.sars.SeqDBReactionGrouper.java
public static void main(String[] args) throws Exception { // Build command line parser. Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build()); }// w w w .j a va 2s .co m 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(SeqDBReactionGrouper.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } // Print help. if (cl.hasOption(OPTION_HELP)) { HELP_FORMATTER.printHelp(SeqDBReactionGrouper.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } // Handle arguments String mongoDBName = cl.getOptionValue(OPTION_DB); MongoDB mongoDB = new MongoDB(LOCAL_HOST, MONGO_PORT, mongoDBName); File outputFile = new File(cl.getOptionValue(OPTION_OUTPUT_PATH)); if (outputFile.isDirectory() || outputFile.exists()) { LOGGER.error("Supplied output file is a directory or already exists."); System.exit(1); } outputFile.createNewFile(); Integer limit = DEFAULT_LIMIT_INFINITY; if (cl.hasOption(OPTION_LIMIT)) { limit = Integer.parseInt(cl.getOptionValue(OPTION_LIMIT)); } LOGGER.info("Only processing first %d entries in Seq DB.", limit); SeqDBReactionGrouper enzymeGrouper = new SeqDBReactionGrouper(mongoDB.getSeqIterator(), mongoDBName, limit); LOGGER.info("Scanning seq db for reactions with same seq."); ReactionGroupCorpus groupCorpus = enzymeGrouper.getReactionGroupCorpus(); LOGGER.info("Writing output to file."); groupCorpus.printToJsonFile(outputFile); LOGGER.info("Complete!"); }
From source file:com.act.lcms.db.io.LoadStandardIonAnalysisTableIntoDB.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build()); }/*from ww w . jav a2 s . c o m*/ CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadStandardIonAnalysisTableIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(LoadStandardIonAnalysisTableIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } File inputFile = new File(cl.getOptionValue(OPTION_FILE_PATH)); if (!inputFile.exists()) { System.err.format("Unable to find input file at %s\n", cl.getOptionValue(OPTION_FILE_PATH)); new HelpFormatter().printHelp(LoadConstructAnalysisTableIntoDB.class.getCanonicalName(), opts, true); System.exit(1); } try (DB db = DB.openDBFromCLI(cl)) { db.getConn().setAutoCommit(false); TSVParser parser = new TSVParser(); parser.parse(inputFile); for (Map<String, String> row : parser.getResults()) { Integer standardIonResultId = Integer.parseInt(row.get( ExportStandardIonResultsFromDB.STANDARD_ION_HEADER_FIELDS.STANDARD_ION_RESULT_ID.name())); String dbValueOfMetlinIon = ExportStandardIonResultsFromDB.NULL_VALUE; StandardIonResult ionResult = StandardIonResult.getInstance().getById(db, standardIonResultId); if (ionResult.getManualOverrideId() != null) { // There is an existing manual override ion in the DB CuratedStandardMetlinIon curatedChemical = CuratedStandardMetlinIon.getBestMetlinIon(db, ionResult.getManualOverrideId()); dbValueOfMetlinIon = curatedChemical.getBestMetlinIon(); } String manualPickOfMetlinIon = row .get(ExportStandardIonResultsFromDB.STANDARD_ION_HEADER_FIELDS.MANUAL_PICK.name()); // If the manual metlin ion pick row is not NULL and it is not the same as the value stored in the DB, then // we need to add a new entry to the curated metlin ion table. if (!manualPickOfMetlinIon.equals(ExportStandardIonResultsFromDB.NULL_VALUE) && !manualPickOfMetlinIon.equals(dbValueOfMetlinIon)) { System.out.format("Manual override has been found, so updating the DB\n"); // A manual entry was created. if (!MS1.VALID_MS1_IONS.contains(manualPickOfMetlinIon)) { System.err.format("ERROR: found invalid chemical name: %s\n", manualPickOfMetlinIon); System.exit(-1); } String note = row.get(ExportStandardIonResultsFromDB.STANDARD_ION_HEADER_FIELDS.NOTE.name()); CuratedStandardMetlinIon result = CuratedStandardMetlinIon.insertCuratedStandardMetlinIonIntoDB( db, LocalDateTime.now(CuratedStandardMetlinIon.utcDateTimeZone), cl.getOptionValue(OPTION_AUTHOR), manualPickOfMetlinIon, note, standardIonResultId); if (result == null) { System.err.format( "WARNING: Could not insert curated entry to the curated metlin ion table\n", manualPickOfMetlinIon); System.exit(-1); } else { StandardIonResult getIonResult = StandardIonResult.getInstance().getById(db, standardIonResultId); getIonResult.setManualOverrideId(result.getId()); if (!StandardIonResult.getInstance().update(db, getIonResult)) { System.err.format( "WARNING: Could not insert manual override id to the standard ion table\n", manualPickOfMetlinIon); System.exit(-1); } else { System.out.format( "Successfully committed updates to the standard ion table and the curated metlin ion table\n"); } } } } db.getConn().commit(); } }
From source file:com.leshazlewood.scms.cli.Main.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption(CONFIG).addOption(DEBUG).addOption(HELP).addOption(VERSION); boolean debug = false; File sourceDir = toFile(System.getProperty("user.dir")); File configFile = null;//from ww w.j a va2 s. c o m File destDir = null; try { CommandLine line = parser.parse(options, args); if (line.hasOption(VERSION.getOpt())) { printVersionAndExit(); } if (line.hasOption(HELP.getOpt())) { printHelpAndExit(options, null, debug, 0); } if (line.hasOption(DEBUG.getOpt())) { debug = true; } if (line.hasOption(CONFIG.getOpt())) { String configFilePath = line.getOptionValue(CONFIG.getOpt()); configFile = toFile(configFilePath); } String[] remainingArgs = line.getArgs(); if (remainingArgs == null) { printHelpAndExit(options, null, debug, -1); } assert remainingArgs != null; if (remainingArgs.length == 1) { String workingDirPath = System.getProperty("user.dir"); sourceDir = toFile(workingDirPath); destDir = toFile(remainingArgs[0]); } else if (remainingArgs.length == 2) { sourceDir = toFile(remainingArgs[0]); destDir = toFile((remainingArgs[1])); } else { printHelpAndExit(options, null, debug, -1); } assert sourceDir != null; assert destDir != null; if (configFile == null) { configFile = new File(sourceDir, DEFAULT_CONFIG_FILE_NAME); } if (configFile.exists()) { if (configFile.isDirectory()) { throw new IllegalArgumentException( "Expected configuration file " + configFile + " is a directory, not a file."); } } else { String msg = "Configuration file not found. Create a default " + DEFAULT_CONFIG_FILE_NAME + " file in your source directory or specify the " + CONFIG + " option to provide the file location."; throw new IllegalStateException(msg); } SiteExporter siteExporter = new SiteExporter(); siteExporter.setSourceDir(sourceDir); siteExporter.setDestDir(destDir); siteExporter.setConfigFile(configFile); siteExporter.init(); siteExporter.execute(); } catch (IllegalArgumentException iae) { exit(iae, debug); } catch (IllegalStateException ise) { exit(ise, debug); } catch (Exception e) { printHelpAndExit(options, e, debug, -1); } }
From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.web1t.LuceneIndexer.java
/** * Execute the indexer. Following parameter are allowed: * //from w w w . j a v a 2 s. co m * * --web1t The folder with all extracted n-gram files * * --outputPath The lucene index folder * * --index (optional) Number of how many indexes should be created. Default: 1 * * @param args */ @SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("web1t") .withDescription("Folder with the web1t extracted documents").hasArg().isRequired().create()); options.addOption(OptionBuilder.withLongOpt("outputPath") .withDescription("File, where the index should be created").hasArg().isRequired().create()); options.addOption(OptionBuilder.withLongOpt("index") .withDescription("(optional) Number of how many indexes should be created. Default: 1").hasArg() .create()); options.addOption(OptionBuilder.withLongOpt("igerman98").withDescription( "(optional) If this argument is set, only words of the german dictionary will be added to the index") .create()); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); int i = 1; if (cmd.hasOption("index")) { i = Integer.valueOf(cmd.getOptionValue("index")); } LuceneIndexer indexer = new LuceneIndexer(new File(cmd.getOptionValue("web1t")), new File(cmd.getOptionValue("outputPath")), i); if (cmd.hasOption("igerman98")) { indexer.setDictionary(new IGerman98Dictionary(new File("src/main/resources/de_DE.dic"), new File("src/main/resources/de_DE.aff"))); } indexer.index(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LuceneIndexer", options); } }
From source file:imageviewer.util.PasswordGenerator.java
public static void main(String[] args) { Option help = new Option("help", "Print this message"); Option file = OptionBuilder.withArgName("file").hasArg().withDescription("Password filename") .create("file"); Option addUser = OptionBuilder.withArgName("add").hasArg().withDescription("Add user profile") .create("add"); Option removeUser = OptionBuilder.withArgName("remove").hasArg().withDescription("Remove user profile") .create("remove"); Option updateUser = OptionBuilder.withArgName("update").hasArg().withValueSeparator() .withDescription("Update user profile").create("update"); file.setRequired(true);/*from w w w . j av a 2 s. co m*/ OptionGroup og = new OptionGroup(); og.addOption(addUser); og.addOption(removeUser); og.addOption(updateUser); og.setRequired(true); Options o = new Options(); o.addOption(help); o.addOption(file); o.addOptionGroup(og); try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(o, args); PasswordGenerator pg = new PasswordGenerator(line); pg.execute(); } catch (UnrecognizedOptionException uoe) { System.err.println("Unknown argument: " + uoe.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("PasswordGenerator", o); System.exit(1); } catch (MissingOptionException moe) { System.err.println("Missing argument: " + moe.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("PasswordGenerator", o); System.exit(1); } catch (Exception exc) { exc.printStackTrace(); } }
From source file:io.sightly.tck.TCK.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt(CLI_EXTRACT).withDescription(CLI_EXTRACT_DESCRIPTION) .hasOptionalArg().withArgName("DIR").create()); options.addOption(OptionBuilder.withLongOpt(CLI_URL).withDescription(CLI_URL_DESCRIPTION).hasOptionalArg() .withArgName("URL").create()); options.addOption(OptionBuilder.withLongOpt(CLI_AUTH_USER).withDescription(CLI_AUTH_USER_DESCRIPTION) .hasOptionalArg().withArgName("USER").create()); options.addOption(OptionBuilder.withLongOpt(CLI_AUTH_PASS).withDescription(CLI_AUTH_PASS_DESCRIPTION) .hasOptionalArg().withArgName("PASS").create()); try {// w w w . j a v a 2s . c om CommandLine line = parser.parse(options, args); if (!line.iterator().hasNext()) { printUsage(options); die(); } else if (line.hasOption(CLI_EXTRACT)) { String extractDir = line.getOptionValue(CLI_EXTRACT); if (StringUtils.isEmpty(extractDir)) { // assume user wants to extract stuff in current directory extractDir = System.getProperty("user.dir"); } INSTANCE.extract(extractDir); LOG.info("Extracted testing resources in folder {}.", extractDir + File.separator + TESTFILES); } else { if (line.hasOption(CLI_URL)) { String url = line.getOptionValue(CLI_URL); if (StringUtils.isEmpty(url)) { LOG.error("Missing value for --" + CLI_URL + " command line option."); printUsage(options); die(); } System.setProperty(Constants.SYS_PROP_SERVER_URL, url); } if (line.hasOption(CLI_AUTH_USER) || line.hasOption(CLI_AUTH_PASS)) { String user = line.getOptionValue(CLI_AUTH_USER); if (StringUtils.isEmpty(user)) { LOG.error("Missing value for --" + CLI_AUTH_USER + " command line option"); printUsage(options); die(); } String pass = line.getOptionValue(CLI_AUTH_PASS); if (StringUtils.isEmpty(pass)) { LOG.error("Missing value for --" + CLI_AUTH_PASS + " command line option"); printUsage(options); die(); } System.setProperty(Constants.SYS_PROP_USER, user); System.setProperty(Constants.SYS_PROP_PASS, pass); } INSTANCE.run(); } } catch (ParseException e) { printUsage(options); die(); } catch (IOException e) { LOG.error("IO Error.", e); die(); } }