List of usage examples for org.apache.commons.cli CommandLineParser parse
CommandLine parse(Options options, String[] arguments) throws ParseException;
From source file:net.ovres.tuxcourser.TuxCourser.java
public static void main(String[] argss) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("WARN|INFO|FINE").hasArg() .withDescription("Set the log level. Valid values include WARN, INFO, and FINE.") .withLongOpt("loglevel").create("l")); options.addOption("h", "help", false, "Displays this help and exits"); options.addOption("v", "version", false, "Displays version information and exits"); options.addOption(OptionBuilder.withArgName("TYPE").hasArg() .withDescription("Sets the output type. Valid values are tux11 and ppracer05").withLongOpt("output") .create());// w w w.j a v a 2 s. co m CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, argss); } catch (ParseException exp) { System.err.println(exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, ""); System.exit(-1); } if (line.hasOption("loglevel")) { String lvl = line.getOptionValue("loglevel"); Level logLevel = Level.parse(lvl); Logger.getLogger("net.ovres.tuxcourser").setLevel(logLevel); } if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, ""); return; } if (line.hasOption("version")) { System.out.println("TuxCourser Version " + Settings.getVersion()); return; } String[] remaining = line.getArgs(); // Initialize all the different item and terrain types ModuleClassLoader.load(); if (remaining.length == 0) { // Just show the gui. //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); new net.ovres.tuxcourser.gui.TuxCourserGui().setVisible(true); } else if (remaining.length == 3) { new TuxCourser().convertCourse(new File(remaining[0]), new File(remaining[1]), remaining[2], TYPE_TUXRACER11); } else { usage(); System.exit(-1); } }
From source file:com.boozallen.cognition.kom.KafakOffsetMonitor.java
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;/* www. j a v a 2s . c o m*/ try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("KafakOffsetMonitor", options); System.exit(1); } KafakOffsetMonitor monitor = new KafakOffsetMonitor(); monitor.zkHosts = cmd.getOptionValue("zkHosts"); monitor.zkRoot = cmd.getOptionValue("zkRoot", "/storm-kafka"); monitor.spoutId = cmd.getOptionValue("spoutId"); monitor.logstashHost = cmd.getOptionValue("logstashHost"); monitor.logstashPort = Integer.parseInt(cmd.getOptionValue("logstashPort")); int refresh = Integer.parseInt(cmd.getOptionValue("refresh", "15")); Timer timer = new Timer(); int period = refresh * 1000; int delay = 0; timer.schedule(monitor, delay, period); }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasic.java
/** * start here//w w w . j a v a 2s . com * <p> * -file src\test\resources\bas\easy\print.bas -verbose true * </p> */ public static void main(String[] args) { try { System.out.println("khubla.com jvmBASIC Compiler"); /* * options */ final Options options = new Options(); Option oo = Option.builder().argName(OUTPUT_OPTION).longOpt(OUTPUT_OPTION).type(String.class).hasArg() .required(false).desc("target directory to output to").build(); options.addOption(oo); oo = Option.builder().argName(FILE_OPTION).longOpt(FILE_OPTION).type(String.class).hasArg() .required(true).desc("file to compile").build(); options.addOption(oo); oo = Option.builder().argName(VERBOSE_OPTION).longOpt(VERBOSE_OPTION).type(String.class).hasArg() .required(false).desc("verbose output").build(); options.addOption(oo); /* * parse */ final CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (final Exception e) { e.printStackTrace(); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("posix", options); System.exit(0); } /* * verbose output? */ final Boolean verbose = Boolean.parseBoolean(cmd.getOptionValue(VERBOSE_OPTION)); /* * get the file */ final String filename = cmd.getOptionValue(FILE_OPTION); final String outputDirectory = cmd.getOptionValue(OUTPUT_OPTION); if (null != filename) { /* * filename */ final String basFileName = System.getProperty("user.dir") + "/" + filename; final File fl = new File(basFileName); if (true == fl.exists()) { /* * show the filename */ System.out.println("Compiling: " + fl.getCanonicalFile()); /* * compiler */ final JVMBasicCompiler jvmBasicCompiler = new JVMBasicCompiler(); /* * compile */ jvmBasicCompiler.compileToClassfile(basFileName, null, outputDirectory, verbose, true, true); } else { throw new Exception("Unable to find: '" + basFileName + "'"); } } else { throw new Exception("File was not supplied"); } } catch (final Exception e) { e.printStackTrace(); } }
From source file:com.aestel.chemistry.openEye.fp.FPDictionarySorter.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); int iCounter = 0; int fpCounter = 0; // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.ism,.sdf,...]"); opt.setRequired(true);// w w w .j av a2s . co m options.addOption(opt); opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4"); opt.setRequired(true); options.addOption(opt); opt = new Option("sampleFract", true, "fraction of input molecules to use (Default=1)"); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } if (args.length != 0) { exitWithHelp(options); } String type = cmd.getOptionValue("fpType"); boolean updateDictionaryFile = false; boolean hashUnknownFrag = false; Fingerprinter fprinter = Fingerprinter.createFingerprinter(type, updateDictionaryFile, hashUnknownFrag); OEMolBase mol = new OEGraphMol(); String inFile = cmd.getOptionValue("i"); oemolistream ifs = new oemolistream(inFile); double fract = 2D; String tmp = cmd.getOptionValue("sampleFract"); if (tmp != null) fract = Double.parseDouble(tmp); Random rnd = new Random(); LearningStrcutureCodeMapper mapper = (LearningStrcutureCodeMapper) fprinter.getMapper(); int dictSize = mapper.getMaxIdx() + 1; int[] freq = new int[dictSize]; while (oechem.OEReadMolecule(ifs, mol)) { iCounter++; if (rnd.nextDouble() < fract) { fpCounter++; Fingerprint fp = fprinter.getFingerprint(mol); for (int bit : fp.getBits()) freq[bit]++; } if (iCounter % 100 == 0) System.err.print("."); if (iCounter % 4000 == 0) { System.err.printf(" %d %d %dsec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); } } System.err.printf("FPDictionarySorter: Read %d structures calculated %d fprints in %d sec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); mapper.reSortDictionary(freq); mapper.writeDictionary(); fprinter.close(); }
From source file:fi.helsinki.cs.iot.kahvihub.KahviHub.java
public static void main(String[] args) throws InterruptedException { // create Options object Options options = new Options(); // add conf file option options.addOption("c", true, "config file"); CommandLineParser parser = new BasicParser(); CommandLine cmd;//from w ww . j a v a 2 s.c o m try { cmd = parser.parse(options, args); String configFile = cmd.getOptionValue("c"); if (configFile == null) { Log.e(TAG, "The config file option was not provided"); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("d", options); System.exit(-1); } else { try { HubConfig hubConfig = ConfigurationFileParser.parseConfigurationFile(configFile); Path libdir = Paths.get(hubConfig.getLibdir()); if (hubConfig.isDebugMode()) { File dir = libdir.toFile(); if (dir.exists() && dir.isDirectory()) for (File file : dir.listFiles()) file.delete(); } final IotHubHTTPD server = new IotHubHTTPD(hubConfig.getPort(), libdir, hubConfig.getHost()); init(hubConfig); try { server.start(); } catch (IOException ioe) { Log.e(TAG, "Couldn't start server:\n" + ioe); System.exit(-1); } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { server.stop(); Log.i(TAG, "Server stopped"); } }); while (true) { Thread.sleep(1000); } } catch (ConfigurationParsingException | IOException e) { System.out.println("1:" + e.getMessage()); Log.e(TAG, e.getMessage()); System.exit(-1); } } } catch (ParseException e) { System.out.println(e.getMessage()); Log.e(TAG, e.getMessage()); System.exit(-1); } }
From source file:de.dominicscheurer.passwords.Main.java
/** * @param args//from ww w. j ava 2s . co m * Command line arguments (see code or output of program when * started with no arguments). */ @SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); Option seedPwdOpt = OptionBuilder.withArgName("Seed Password").isRequired().hasArg() .withDescription("Password used as a seed").withLongOpt("seed-password").create("s"); Option serviceIdOpt = OptionBuilder.withArgName("Service Identifier").isRequired().hasArg() .withDescription("The service that the password is created for, e.g. facebook.com") .withLongOpt("service-identifier").create("i"); Option pwdLengthOpt = OptionBuilder.withArgName("Password Length").withType(Integer.class).hasArg() .withDescription("Length of the password in characters").withLongOpt("pwd-length").create("l"); Option specialChars = OptionBuilder.withArgName("With special chars (TRUE|false)").withType(Boolean.class) .hasArg().withDescription("Set to true if special chars !-_?=@/+* are desired, else false") .withLongOpt("special-chars").create("c"); Option suppressPwdOutpOpt = OptionBuilder .withDescription("Suppress password output (copy to clipboard only)").withLongOpt("hide-password") .hasArg(false).create("x"); Option helpOpt = OptionBuilder.withDescription("Prints this help message").withLongOpt("help").create("h"); options.addOption(seedPwdOpt); options.addOption(serviceIdOpt); options.addOption(pwdLengthOpt); options.addOption(specialChars); options.addOption(suppressPwdOutpOpt); options.addOption(helpOpt); CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { SafePwdGen.printHelp(options); System.exit(0); } int pwdLength = STD_PWD_LENGTH; if (cmd.hasOption("l")) { pwdLength = new Integer(cmd.getOptionValue("l")); } boolean useSpecialChars = true; if (cmd.hasOption("c")) { useSpecialChars = new Boolean(cmd.getOptionValue("c")); } if (pwdLength > MAX_PWD_LENGTH_64 && !useSpecialChars) { System.out.println(PASSWORD_SIZE_TOO_BIG + MAX_PWD_LENGTH_64); } if (pwdLength > MAX_PWD_LENGTH_71 && useSpecialChars) { System.out.println(PASSWORD_SIZE_TOO_BIG + MAX_PWD_LENGTH_71); } boolean suppressPwdOutput = cmd.hasOption('x'); String pwd = SafePwdGen.createPwd(cmd.getOptionValue("s"), cmd.getOptionValue("i"), pwdLength, useSpecialChars); if (!suppressPwdOutput) { System.out.print(GENERATED_PASSWORD); System.out.println(pwd); } System.out.println(CLIPBOARD_COPIED_MSG); SystemClipboardInterface.copy(pwd); System.in.read(); } catch (ParseException e) { System.out.println(e.getLocalizedMessage()); SafePwdGen.printHelp(options); } catch (UnsupportedEncodingException e) { System.out.println(e.getLocalizedMessage()); } catch (NoSuchAlgorithmException e) { System.out.println(e.getLocalizedMessage()); } catch (IOException e) { System.out.println(e.getLocalizedMessage()); } }
From source file:com.c4om.xsdfriendlyvalidator.XSDFriendlyValidatorLauncher.java
/** * Method called at application start./*from ww w.j a v a 2 s .c o m*/ * * @param args command line args */ public static void main(String[] args) throws Exception { CommandLineParser parser = new BasicParser(); CommandLine commandLine1 = parser.parse(OPTIONS, args); CommandLine commandLine = commandLine1; if (commandLine.hasOption(OPTION_NAME_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(COMMAND_LINE_SYNTAX, OPTIONS); System.exit(0); } else if (!commandLine.hasOption(OPTION_NAME_INPUT_FILES)) { System.err.println("You must specify input files. Invoke with --help to see how."); System.exit(1); } String[] inputFileOptionValues = commandLine.getOptionValues(OPTION_NAME_INPUT_FILES); List<Document> inputFilesList = getListOfInputDocumentsFromCommandLine(inputFileOptionValues); String[] schemasOptionValues = commandLine.getOptionValues(OPTION_NAME_SCHEMAS); Map<String, Document> schemasMap = getSchemaFilesFromCommandLine(schemasOptionValues); XSDFriendlyValidator validator = new XSDFriendlyValidatorImpl(); ValidationResults validationResults = validator.validate(inputFilesList, Arrays.asList(inputFileOptionValues), schemasMap); System.out.println(validationResults.toString()); }
From source file:com.cloudera.recordbreaker.schemadict.SchemaDictionary.java
public static void main(String argv[]) throws IOException { boolean shouldDump = false; boolean shouldAdd = false; File avroDataFile = null;/*w w w.j a va 2s. c o m*/ String dictMessage = null; CommandLine cmd = null; Options options = new Options(); options.addOption("?", false, "Help for command-line"); options.addOption("d", false, "Dump contents of schema dictionary"); options.addOption("a", true, "Add datafile to new schema dictionary element"); options.addOption("m", true, "Add comment message as part of new schema dictionary element"); try { CommandLineParser parser = new PosixParser(); cmd = parser.parse(options, argv); } catch (ParseException e) { HelpFormatter fmt = new HelpFormatter(); fmt.printHelp("SchemaDictionary", options, true); System.err.println("Required input: <schemadictionary>"); System.exit(-1); } if (cmd.hasOption("?")) { HelpFormatter fmt = new HelpFormatter(); fmt.printHelp("SchemaDictionary", options, true); System.err.println("Required input: <schemadictionary>"); System.exit(0); } if (cmd.hasOption("d")) { shouldDump = true; } if (cmd.hasOption("a")) { avroDataFile = new File(cmd.getOptionValue("a")).getCanonicalFile(); } if (cmd.hasOption("m")) { dictMessage = cmd.getOptionValue("m"); if (cmd.hasOption("a")) { shouldAdd = true; } } if ((!shouldAdd) && (cmd.hasOption("a") || cmd.hasOption("m"))) { System.err.println("Must indicate -a AND -m to add new schema dictionary item"); HelpFormatter fmt = new HelpFormatter(); fmt.printHelp("SchemaDictionary", options, true); System.err.println("Required input: <schemadictionary>"); System.exit(0); } String[] argArray = cmd.getArgs(); if (argArray.length == 0) { System.err.println("No schema dictionary path provided."); HelpFormatter fmt = new HelpFormatter(); fmt.printHelp("SchemaDictionary", options, true); System.err.println("Required input: <schemadictionary>"); System.exit(0); } File dictionaryDir = new File(argArray[0]).getCanonicalFile(); SchemaDictionary dict = new SchemaDictionary(dictionaryDir); if (shouldAdd) { dict.addDictionaryElt(avroDataFile, dictMessage); } if (shouldDump) { int counter = 1; for (SchemaDictionaryEntry entry : dict.contents()) { System.err.println("" + counter + ". " + entry.getInfo()); System.err.println(entry.getSchema()); System.err.println(); counter++; } int numItems = counter - 1; System.err.println( "Dictionary at " + dictionaryDir.getCanonicalPath() + " has " + numItems + " item(s)."); } }
From source file:edu.mines.acmX.exhibit.runner.ModuleManagerRunner.java
/** * Main function for the ModuleManager framework. Creates an instance of * ModuleManager and runs it./*from w w w . j a va2 s. c o m*/ * * Arguments: The single argument that is needed is the path to a valid * module manager manifest file. This is specified using the --manifest arg. * For additional documentation on running the module manager please refer * to the wiki in Common.REPOSITORY */ public static void main(String[] args) { CommandLineParser cl = new GnuParser(); CommandLine cmd; Options opts = generateCLOptions(); try { cmd = cl.parse(opts, args); if (cmd.hasOption("help")) { printHelp(opts); } else { if (cmd.hasOption("manifest")) { ModuleManager.configure(cmd.getOptionValue("manifest")); } else { System.out.println("A Module Manager Manifest is required to run the module manager" + "Please specify with the --manifest switch"); System.exit(1); } ModuleManager m; m = ModuleManager.getInstance(); //publicizeRmiInterface(m, RMI_REGISTRY_PORT); m.run(); } } catch (ParseException e) { printHelp(opts); logger.error("Incorrect command line arguments"); e.printStackTrace(); } catch (ManifestLoadException e) { logger.fatal("Could not load the module manager manifest"); e.printStackTrace(); } catch (ModuleLoadException e) { logger.fatal("Could not load the default module"); e.printStackTrace(); } }
From source file:dhtaccess.tools.Remove.java
public static void main(String[] args) { int ttl = 3600; // parse properties Properties prop = System.getProperties(); String gateway = prop.getProperty("dhtaccess.gateway"); if (gateway == null || gateway.length() <= 0) { gateway = DEFAULT_GATEWAY;/* ww w. jav a2 s . c o m*/ } // parse options Options options = new Options(); options.addOption("h", "help", false, "print help"); options.addOption("g", "gateway", true, "gateway URI, list at http://opendht.org/servers.txt"); options.addOption("t", "ttl", true, "how long (in seconds) to store the value"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println("There is an invalid option."); e.printStackTrace(); System.exit(1); } String optVal; if (cmd.hasOption('h')) { usage(COMMAND); System.exit(1); } optVal = cmd.getOptionValue('g'); if (optVal != null) { gateway = optVal; } optVal = cmd.getOptionValue('t'); if (optVal != null) { ttl = Integer.parseInt(optVal); } args = cmd.getArgs(); // parse arguments if (args.length < 3) { usage(COMMAND); System.exit(1); } byte[] key = null, value = null, secret = null; try { key = args[0].getBytes(ENCODE); value = args[1].getBytes(ENCODE); secret = args[2].getBytes(ENCODE); } catch (UnsupportedEncodingException e1) { // NOTREACHED } // prepare for RPC DHTAccessor accessor = null; try { accessor = new DHTAccessor(gateway); } catch (MalformedURLException e) { e.printStackTrace(); System.exit(1); } // RPC int res = accessor.remove(key, value, ttl, secret); String resultString; switch (res) { case 0: resultString = "Success"; break; case 1: resultString = "Capacity"; break; case 2: resultString = "Again"; break; default: resultString = "???"; } System.out.println(resultString); }