List of usage examples for org.apache.commons.cli Options Options
Options
From source file:fr.tpt.atlanalyser.tests.TestOldAGTExpPost2Pre.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // URL resource = Thread.currentThread().getContextClassLoader() // .getResource("OldAGTExp"); // System.out.println(resource.toString()); // File f = new File(resource.getPath()); // System.out.println(f.toString()); // System.out.println(f.isDirectory()); // System.exit(0); Options options = new Options(); options.addOption(/*from w ww . j av a 2 s . c o m*/ OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j")); options.addOption(OptionBuilder.withDescription("Display help").create("h")); CommandLineParser parser = new BasicParser(); int jobs = 1; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { new HelpFormatter().printHelp(TestOldAGTExpPost2Pre.class.getSimpleName(), options); System.exit(0); } if (cmd.hasOption("j")) { jobs = Integer.parseInt(cmd.getOptionValue("j")); } } catch (Exception e) { System.out.println("Incorrect command line arguments"); new HelpFormatter().printHelp(TestOldAGTExpPost2Pre.class.getSimpleName(), options); System.exit(1); } new TestOldAGTExpPost2Pre(models().iterator().next()[0], jobs).testPost2Pre(); }
From source file:cc.twittertools.index.ExtractTermStatisticsFromIndex.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("index").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("min").create(MIN_OPTION)); CommandLine cmdline = null;/*from www . ja v a2 s. c o m*/ 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(ExtractTermStatisticsFromIndex.class.getName(), options); System.exit(-1); } String indexLocation = cmdline.getOptionValue(INDEX_OPTION); int min = cmdline.hasOption(MIN_OPTION) ? Integer.parseInt(cmdline.getOptionValue(MIN_OPTION)) : 1; PrintStream out = new PrintStream(System.out, true, "UTF-8"); IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexLocation))); Terms terms = SlowCompositeReaderWrapper.wrap(reader).terms(StatusField.TEXT.name); TermsEnum termsEnum = terms.iterator(TermsEnum.EMPTY); long missingCnt = 0; int skippedTerms = 0; BytesRef bytes = new BytesRef(); while ((bytes = termsEnum.next()) != null) { byte[] buf = new byte[bytes.length]; System.arraycopy(bytes.bytes, 0, buf, 0, bytes.length); String term = new String(buf, "UTF-8"); int df = termsEnum.docFreq(); long cf = termsEnum.totalTermFreq(); if (df < min) { skippedTerms++; missingCnt += cf; continue; } out.println(term + "\t" + df + "\t" + cf); } reader.close(); out.close(); System.err.println("skipped terms: " + skippedTerms + ", cnt: " + missingCnt); }
From source file:de.dknapps.pswgendesktop.main.PswGenDesktop.java
/** * Hier werden die Kommandozeilenparameter analysiert und die Anwendung gestartet. *//* ww w . ja va2 s .co m*/ public static void main(String[] args) throws IOException { Options options = new Options(); Option help = new Option("help", "print this message"); @SuppressWarnings("static-access") Option services = OptionBuilder.withArgName("file").hasArg() .withDescription("use given file to store services").create("services"); @SuppressWarnings("static-access") Option upgrade = OptionBuilder.withArgName("passphrase").hasArg() .withDescription("converts and re-encrypts services to new format if not too old") .create("upgrade"); options.addOption(help); options.addOption(services); options.addOption(upgrade); CommandLineParser parser = new GnuParser(); // GnuParser => mehrbuchstabige Optionen CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); // line bleibt null, dann kommt die Hilfe } if (line == null || line.hasOption("help")) { // Hilfe ausgeben => nur das tun HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pswgen", options); } else if (line.hasOption("upgrade")) { // Datei umformatieren => nur das tun String servicesFilename = line.getOptionValue("services", CoreConstants.SERVICES_FILENAME); String passphrase = line.getOptionValue("upgrade"); PswGenCtl ctl = new PswGenCtl(servicesFilename); ctl.upgradeServiceInfoList(passphrase); } else { String servicesFilename = line.getOptionValue("services", CoreConstants.SERVICES_FILENAME); PswGenCtl ctl = new PswGenCtl(servicesFilename); ctl.start(); // Anwendung starten, PswGenCtl terminiert die VM } }
From source file:net.sf.brunneng.iqdb.db.DBWorker.java
public static void main(String[] args) { Options options = new Options(); Option actionOpt = new Option("a", "action", true, "The action on db, which should be executed." + BR_LINE + " Possible actions: " + BR_LINE + createActionsDescription()); actionOpt.setRequired(true);/*from w ww . ja v a 2s. c om*/ options.addOption(actionOpt); CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, args); String actionStr = commandLine.getOptionValue("action"); DBAction action = null; try { action = DBAction.valueOf(actionStr); } catch (IllegalStateException exc) { System.out.println("Unknown action: " + actionStr); System.out.println("Possible actions: " + createActionsDescription()); System.exit(-1); } DBWorker worker = new DBWorker(action, null, null, null); worker.execute(); } catch (ParseException exc) { System.out.println("Unable to parse command line arguments. Error: " + exc.getMessage()); printUsageAndExit(options); } }
From source file:craterdog.security.DigitalNotaryMain.java
public static void main(String[] args) throws ParseException, IOException { HelpFormatter help = new HelpFormatter(); Options options = new Options(); options.addOption("help", false, "print this message"); options.addOption("pubfile", true, "public key input file"); options.addOption("prvfile", true, "private key input file"); try {//w w w .ja v a2 s . c o m CommandLine cli = new BasicParser().parse(options, args); String pubfile = cli.getOptionValue("pubfile"); String prvfile = cli.getOptionValue("prvfile"); NotaryKey notaryKey = notarization.generateNotaryKey(); if (pubfile != null || prvfile != null) { if (pubfile == null) throw new MissingArgumentException("Missing option: pubfile"); if (prvfile == null) throw new MissingArgumentException("Missing option: prvfile"); CertificateManager manager = new RsaCertificateManager(); PublicKey publicKey = manager.decodePublicKey(FileUtils.readFileToString(new File(pubfile))); char[] password = System.console().readPassword("input private key password: "); PrivateKey privateKey = manager.decodePrivateKey(FileUtils.readFileToString(new File(prvfile)), password); notaryKey.signingKey = privateKey; notaryKey.verificationKey = publicKey; // make sure it works DigitalSeal seal = notarization.notarizeDocument("test document", "test document", notaryKey); notarization.documentIsValid("test document", seal, publicKey); } char[] password = System.console().readPassword("verficationKey password: "); System.out.println(notarization.serializeNotaryKey(notaryKey, password)); } catch (MissingArgumentException | FileNotFoundException ex) { System.out.println(ex.getMessage()); help.printHelp(CMD_LINE_SYNTAX, options); System.exit(1); } }
From source file:fr.tpt.s3.mcdag.scheduling.Main.java
public static void main(String[] args) throws IOException, InterruptedException { /* Command line options */ Options options = new Options(); Option input = new Option("i", "input", true, "MC-DAG XML Models"); input.setRequired(true);/*w w w .j a v a 2 s. c o m*/ input.setArgs(Option.UNLIMITED_VALUES); // Sets maximum number of threads to be launched options.addOption(input); Option outSched = new Option("os", "out-scheduler", false, "Write the scheduling tables into a file."); outSched.setRequired(false); options.addOption(outSched); Option outPrism = new Option("op", "out-prism", false, "Write PRISM model into a file."); outPrism.setRequired(false); options.addOption(outPrism); Option jobs = new Option("j", "jobs", true, "Number of threads to be launched."); jobs.setRequired(false); options.addOption(jobs); Option debugOpt = new Option("d", "debug", false, "Enabling debug."); debugOpt.setRequired(false); options.addOption(debugOpt); Option preemptOpt = new Option("p", "preempt", false, "Count for preemptions."); preemptOpt.setRequired(false); options.addOption(preemptOpt); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); formatter.printHelp("MC-DAG framework", options); System.exit(1); return; } String inputFilePath[] = cmd.getOptionValues("input"); boolean bOutSched = cmd.hasOption("out-scheduler"); boolean bOutPrism = cmd.hasOption("out-prism"); boolean debug = cmd.hasOption("debug"); boolean preempt = cmd.hasOption("preempt"); boolean levels = cmd.hasOption("n-levels"); int nbFiles = inputFilePath.length; int nbJobs = 1; if (cmd.hasOption("jobs")) nbJobs = Integer.parseInt(cmd.getOptionValue("jobs")); if (debug) System.out.println("[DEBUG] Launching " + inputFilePath.length + " thread(s)."); int i_files = 0; ExecutorService executor = Executors.newFixedThreadPool(nbJobs); /* Launch threads to solve allocation */ while (i_files != nbFiles) { SchedulingThread ft = new SchedulingThread(inputFilePath[i_files], bOutSched, bOutPrism, debug, preempt); ft.setLevels(levels); executor.execute(ft); i_files++; } executor.shutdown(); executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); System.out.println("[FRAMEWORK Main] DONE"); }
From source file:fr.tpt.atlanalyser.tests.TestForPaperPost2Pre.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // URL resource = Thread.currentThread().getContextClassLoader() // .getResource("OldAGTExp"); // System.out.println(resource.toString()); // File f = new File(resource.getPath()); // System.out.println(f.toString()); // System.out.println(f.isDirectory()); // System.exit(0); Options options = new Options(); options.addOption(/*from w ww. j a v a 2s .com*/ OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j")); options.addOption(OptionBuilder.withDescription("Display help").create("h")); CommandLineParser parser = new BasicParser(); int jobs = 1; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { new HelpFormatter().printHelp(TestForPaperPost2Pre.class.getSimpleName(), options); System.exit(0); } if (cmd.hasOption("j")) { jobs = Integer.parseInt(cmd.getOptionValue("j")); } } catch (Exception e) { System.out.println("Incorrect command line arguments"); new HelpFormatter().printHelp(TestForPaperPost2Pre.class.getSimpleName(), options); System.exit(1); } new TestForPaperPost2Pre(models().get(0)[0], jobs).testPost2Pre(); }
From source file:fr.tpt.atlanalyser.tests.TestPointsToLinesPost2Pre.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // URL resource = Thread.currentThread().getContextClassLoader() // .getResource("OldAGTExp"); // System.out.println(resource.toString()); // File f = new File(resource.getPath()); // System.out.println(f.toString()); // System.out.println(f.isDirectory()); // System.exit(0); Options options = new Options(); options.addOption(/*w w w . j a va 2 s .c o m*/ OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j")); options.addOption(OptionBuilder.withDescription("Display help").create("h")); CommandLineParser parser = new BasicParser(); int jobs = 1; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { new HelpFormatter().printHelp(TestPointsToLinesPost2Pre.class.getSimpleName(), options); System.exit(0); } if (cmd.hasOption("j")) { jobs = Integer.parseInt(cmd.getOptionValue("j")); } } catch (Exception e) { System.out.println("Incorrect command line arguments"); new HelpFormatter().printHelp(TestPointsToLinesPost2Pre.class.getSimpleName(), options); System.exit(1); } new TestPointsToLinesPost2Pre(models().get(1)[0], jobs).testPost2Pre(); }
From source file:jp.primecloud.auto.tool.management.main.Main.java
public static void main(String args[]) { Options options = new Options(); options.addOption("Z", false, "Zabbix mode"); options.addOption("U", false, "UPDATE mode"); options.addOption("S", false, "SELECT mode"); options.addOption("C", false, "Create Mode"); options.addOption("P", false, "Show Platform"); options.addOption("L", false, "Show Users"); options.addOption("E", false, "Ecrypt UserPassword"); options.addOption("I", false, "IaasGateway Mode"); options.addOption("A", false, "PCC-API Genarate ID or Key Mode"); options.addOption("W", false, "Decrypt UserPassword"); options.addOption("username", true, "Create the username"); options.addOption("password", true, "Create the password"); options.addOption("firstname", true, "Create the firstname"); options.addOption("familyname", true, "Create the familyname"); options.addOption("userno", true, "Create the userno"); options.addOption("dburl", "connectionurl", true, "PrimeCloud Controller database url"); options.addOption("dbuser", "username", true, "PrimeCloud Controller database username"); options.addOption("dbpass", "password", true, "PrimeCloud Controller database password"); options.addOption("sql", true, "SQL"); options.addOption("columnname", true, "columnName"); options.addOption("columntype", true, "columnType"); options.addOption("salt", true, "Salt"); OptionBuilder.withLongOpt("prepared"); OptionBuilder.hasArgs();//from www . j av a 2 s.c o m OptionBuilder.withDescription("execute as PreparedStatement"); OptionBuilder.withArgName("params"); Option optionPrepared = OptionBuilder.create(); options.addOption(optionPrepared); // for Zabbix options.addOption("enable", false, "enable"); options.addOption("disable", false, "disable"); options.addOption("get", false, "getUser from zabbix"); options.addOption("check", false, "API setting check for zabbix"); options.addOption("config", true, "Property can obtain from management-config.properties"); options.addOption("platformkind", true, "Platform kind. e.g. ec2 and ec2_vpc or vmware"); options.addOption("platformname", true, "Platform can obtain from auto-config.xml"); options.addOption("platformno", true, "Platform can obtain from auto-config.xml"); // for IaasGateway(AWS, Cloudstack) options.addOption("keyname", true, "import your key pair as keyName"); options.addOption("publickey", true, "import your public key"); // for PCC options.addOption("accessid", true, "accessid for PCC-API"); options.addOption("secretkey", true, "secretkey for PCC-API"); options.addOption("generatetype", true, "genarateType for PCC-API"); options.addOption("h", "help", false, "help"); CommandLineParser parser = new BasicParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException e) { System.out.println( "???????? -h?????????"); return; } if (commandLine.hasOption("h")) { HelpFormatter f = new HelpFormatter(); f.printHelp("PCC script ", options); } ManagementConfigLoader.init(); //? //Zabbix? if (commandLine.hasOption("Z")) { if (commandLine.hasOption("C")) { //Zabbix? ZabbixMain.createExecute(commandLine); } else if (commandLine.hasOption("U")) { //Zabbix ZabbixMain.updateExecute(commandLine); } else if (commandLine.hasOption("disable")) { //Zabbix ZabbixMain.disableExecute(commandLine); } else if (commandLine.hasOption("enable")) { //Zabbix ZabbixMain.enableExecute(commandLine); } else if (commandLine.hasOption("get")) { //Zabbix? ZabbixMain.getUser(commandLine); } else if (commandLine.hasOption("check")) { //Zabbix?? ZabbixMain.checkApiVersion(); } //PCC? } else if (commandLine.hasOption("U")) { if (commandLine.hasOption("prepared")) { SQLMain.updateExecutePrepared(commandLine); } else { //Update? SQLMain.updateExecute(commandLine); } } else if (commandLine.hasOption("S")) { //Select? SQLMain.selectExecute(commandLine); } else if (commandLine.hasOption("P")) { //? ConfigMain.showPlatforms(); } else if (commandLine.hasOption("L")) { //PCC? UserService.showUserPlatform(); } else if (commandLine.hasOption("config")) { //??? ConfigMain.getProperty(commandLine.getOptionValue("config")); } else if (commandLine.hasOption("platformname") && commandLine.hasOption("platformkind")) { //?????? ConfigMain.getPlatformNo(commandLine.getOptionValue("platformname"), commandLine.getOptionValue("platformkind")); } else if (commandLine.hasOption("E")) { //PCC?? UserService.encryptUserPassword(commandLine.getOptionValue("password")); } else if (commandLine.hasOption("I")) { //IaasGatewayCall??AWS or Cloudstack??? IaasGatewayMain.importExecute(commandLine); } else if (commandLine.hasOption("A")) { PccApiGenerateService.genarate(commandLine); } else if (commandLine.hasOption("W")) { //PCC?? UserService.decryptUserPassword(commandLine.getOptionValue("password"), commandLine.getOptionValue("salt")); } }
From source file:de.akquinet.android.rindirect.Main.java
/** * Main method./*from w w w .ja v a 2 s. c om*/ * This methods defines the arguments, parse them and launch the R indirection * generation. * @param args the arguments. * @throws ParseException * @throws IOException */ public static void main(String[] args) throws ParseException, Exception { LOGGER.setLevel(Level.WARNING); Options options = new Options(); options.addOption("P", "package", true, "destination package (mandatory)") .addOption("R", "classname", true, "generated java file [R]") .addOption("D", "destination", true, "the root of the destination [src]") .addOption("I", "input", true, "R file [searched in the 'gen' folder]") .addOption("V", "verbose", false, "Enable verbose mode"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); RIndirect rindirect = configure(cmd); rindirect.generate(); }