Example usage for org.apache.commons.cli CommandLine hasOption

List of usage examples for org.apache.commons.cli CommandLine hasOption

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine hasOption.

Prototype

public boolean hasOption(char opt) 

Source Link

Document

Query to see if an option has been set.

Usage

From source file:com.bialx.ebics.FDL.java

public static void main(String[] args) throws Exception {
    String userId = "";
    Boolean isTest = false;/*from   w  w w  .  j ava  2s .  c  om*/
    Date startDate = null;
    Date endDate = null;

    SimpleDateFormat dtFormat = new SimpleDateFormat("yyyyMMdd");

    CommandLineParser parser = new DefaultParser();

    BialxOptions options = new BialxOptions();

    // Parse the program arguments
    CommandLine commandLine = parser.parse(options, args);

    // optional values
    if (commandLine.hasOption('s')) {
        startDate = dtFormat.parse(commandLine.getOptionValue('s'));
    }

    if (commandLine.hasOption('e')) {
        endDate = dtFormat.parse(commandLine.getOptionValue('e'));
    }

    if (commandLine.hasOption('t')) {
        isTest = true;
    }

    FDL fdl;
    PasswordCallback pwdHandler;
    Product product;

    fdl = new FDL();

    pwdHandler = new UserPasswordHandler(userId, CERT_PASSWORD);

    product = new Product("Bial-x EBICS FDL", Locale.FRANCE, null);

    if (commandLine.hasOption(BialxOptions.OPTION_CREATION)
            && !commandLine.hasOption(BialxOptions.OPTION_DOWNLOAD)) {
        if (options.checkCreationOptions(commandLine)) {
            CreationOptions co = options.loadCreationOptions(commandLine);
            fdl.configuration.getLogger().info(String.format("Banque : %s", co.getBankName()));
            fdl.configuration.getLogger().info(String.format("Host : %s", co.getHostId()));
            fdl.configuration.getLogger().info(String.format("URL : %s", co.getBankUrl()));
            fdl.configuration.getLogger().info(String.format("Partner : %s", co.getPartnerId()));
            fdl.configuration.getLogger().info(String.format("User : %s", co.getUserId()));
            User user = fdl.createUser(co.getUserId(), co.getHostId(), co.getPartnerId(), co.getBankName(),
                    co.getBankUrl(), pwdHandler);
            fdl.sendHPBRequest(user, product);
        } else {
            fdl.configuration.getLogger().info("Vrifiez les paramtres de la commande.");
            System.exit(0);
        }
    }

    if (!commandLine.hasOption(BialxOptions.OPTION_CREATION)
            && commandLine.hasOption(BialxOptions.OPTION_DOWNLOAD)) {
        if (options.checkDownloadOptions(commandLine)) {
            DownloadOptions dop = options.loadDownloadOptions(commandLine);
            fdl.configuration.getLogger().info(String.format("Banque : %s", dop.getHostId()));
            fdl.configuration.getLogger().info(String.format("Host : %s", dop.getHostId()));
            fdl.configuration.getLogger().info(String.format("Partner : %s", dop.getPartnerId()));
            fdl.configuration.getLogger().info(String.format("User : %s", dop.getUserId()));
            fdl.configuration.getLogger().info(String.format("Format : %s", dop.getFormat()));
            fdl.configuration.getLogger().info(String.format("Destination : %s", dop.getDestination()));
            if (startDate != null) {
                fdl.configuration.getLogger()
                        .info(String.format("Date dbut : %s", dtFormat.format(startDate)));
            }
            if (endDate != null) {
                fdl.configuration.getLogger().info(String.format("Date fin : %s", dtFormat.format(endDate)));
            }
            fdl.loadUser(dop.getHostId(), dop.getPartnerId(), dop.getUserId(), pwdHandler);
            fdl.fetchFile(dop.getDestination(), dop.getUserId(), dop.getFormat(), product, OrderType.FDL,
                    isTest, startDate, endDate);
        } else {
            fdl.configuration.getLogger().info("Vrifiez les paramtres de la commande.");
            System.exit(0);
        }
    }

    if (commandLine.hasOption(BialxOptions.OPTION_DOWNLOAD)
            && commandLine.hasOption(BialxOptions.OPTION_CREATION)) {
        fdl.configuration.getLogger().error("Impossible d'avoir les options C et D dans la mme commande.");
        System.exit(0);
    }

    fdl.quit();
}

From source file:com.jolbox.benchmark.BenchmarkLaunch.java

/**
 * @param args/*from   w w  w. java2 s.c  o  m*/
 * @throws ClassNotFoundException 
 * @throws PropertyVetoException 
 * @throws SQLException 
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 * @throws InterruptedException 
 * @throws SecurityException 
 * @throws IllegalArgumentException 
 * @throws NamingException 
 * @throws ParseException 
 * @throws IOException 
 */
public static void main(String[] args) throws ClassNotFoundException, SQLException, PropertyVetoException,
        IllegalArgumentException, SecurityException, InterruptedException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException, NamingException, ParseException, IOException {

    Options options = new Options();
    options.addOption("t", "threads", true, "Max number of threads");
    options.addOption("s", "stepping", true, "Stepping of threads");
    options.addOption("p", "poolsize", true, "Pool size");
    options.addOption("h", "help", false, "Help");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("benchmark.jar", options);
        System.exit(1);
    }

    BenchmarkTests.threads = 400;
    BenchmarkTests.stepping = 5;
    BenchmarkTests.pool_size = 200;
    if (cmd.hasOption("t")) {
        BenchmarkTests.threads = Integer.parseInt(cmd.getOptionValue("t", "400"));
    }
    if (cmd.hasOption("s")) {
        BenchmarkTests.stepping = Integer.parseInt(cmd.getOptionValue("s", "20"));
    }
    if (cmd.hasOption("p")) {
        BenchmarkTests.pool_size = Integer.parseInt(cmd.getOptionValue("p", "200"));
    }

    System.out.println("Starting benchmark tests with " + BenchmarkTests.threads + " threads (stepping "
            + BenchmarkTests.stepping + ") using pool size of " + BenchmarkTests.pool_size + " connections");

    new MockJDBCDriver();
    BenchmarkTests tests = new BenchmarkTests();

    plotLineGraph(tests.testMultiThreadedConstantDelay(0), 0, false);
    plotLineGraph(tests.testMultiThreadedConstantDelay(10), 10, false);
    plotLineGraph(tests.testMultiThreadedConstantDelay(25), 25, false);
    plotLineGraph(tests.testMultiThreadedConstantDelay(50), 50, false);
    plotLineGraph(tests.testMultiThreadedConstantDelay(75), 75, false);

    plotBarGraph("Single Thread", "bonecp-singlethread-poolsize-" + BenchmarkTests.pool_size + "-threads-"
            + BenchmarkTests.threads + ".png", tests.testSingleThread());
    plotBarGraph(
            "Prepared Statement\nSingle Threaded", "bonecp-preparedstatement-single-poolsize-"
                    + BenchmarkTests.pool_size + "-threads-" + BenchmarkTests.threads + ".png",
            tests.testPreparedStatementSingleThread());
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(0), 0, true);
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(10), 10, true);
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(25), 25, true);
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(50), 50, true);
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(75), 75, true);

}

From source file:com.movielabs.availstool.AvailsTool.java

public static void main(String[] args) throws Exception {
    String fileName, outFile, sheetName;
    int sheetNum = -1;

    Logger log = LogManager.getLogger(AvailsTool.class.getName());
    log.info("Initializing logger");

    Options options = new Options();
    options.addOption(Opts.v.name(), false, "verbose mode");
    options.addOption(Opts.s.name(), true, "specify sheet");
    options.addOption(Opts.f.name(), true, "specify file name");
    options.addOption(Opts.o.name(), true, "specify output file name");
    options.addOption(Opts.sstoxml.name(), false, "convert avails spreadsheet to XML");
    options.addOption(Opts.xmltoss.name(), false, "convert avails XML to a spreadsheet");
    options.addOption(Opts.dumpsheet.name(), false, "dump a single sheet from a spreadsheet");
    options.addOption(Opts.dumpss.name(), false, "dump a spreadsheet file");
    options.addOption(Opts.wx.name(), false, "treat warning as fatal error");
    options.addOption(Opts.clean.name(), false, "clean up data entries");

    CommandLineParser cli = new DefaultParser();

    try {//from   w  ww  .j  a  va 2  s .  co m
        CommandLine cmd = cli.parse(options, args);
        boolean optToXML = cmd.hasOption(Opts.sstoxml.name());
        boolean optToSS = cmd.hasOption(Opts.xmltoss.name());
        boolean optDumpSS = cmd.hasOption(Opts.dumpss.name());
        boolean optDumpSheet = cmd.hasOption(Opts.dumpsheet.name());
        fileName = cmd.getOptionValue(Opts.f.name());
        sheetName = cmd.getOptionValue(Opts.s.name());
        boolean clean = cmd.hasOption(Opts.clean.name());
        boolean wx = cmd.hasOption(Opts.wx.name());
        boolean verbose = cmd.hasOption(Opts.v.name());
        AvailSS ss;
        AvailsSheet as;
        String message;

        if (sheetName != null) {
            Pattern pat = Pattern.compile("^\\d+$");
            Matcher m = pat.matcher(sheetName);
            if (m.matches())
                sheetNum = Integer.parseInt(sheetName);
        }

        if (fileName == null)
            throw new ParseException("input file not specified");

        if (!(optToXML | optToSS | optDumpSS | optDumpSheet))
            throw new ParseException("missing operation");

        if (optToXML) {
            if (optToSS | optDumpSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            outFile = cmd.getOptionValue(Opts.o.name());
            if (outFile == null)
                throw new ParseException("output file not specified");

            ss = new AvailSS(fileName, log, wx, clean);
            if (sheetNum < 0)
                as = ss.addSheet(sheetName);
            else
                as = ss.addSheet(sheetNum);
            message = "toXML file: " + fileName + " sheet: " + sheetName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            log.info("Options: -clean:" + clean + "; -wx:" + wx + "; output file: " + outFile);
            String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
            String shortDesc = String.format("generated XML from %s:%s on %s", fileName, sheetName, timeStamp);
            as.makeXMLFile(outFile, shortDesc);
        } else if (optToSS) {
            if (optToXML | optDumpSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            // TODO implement this
            outFile = cmd.getOptionValue(Opts.o.name());
            if (outFile == null)
                throw new ParseException("output file not specified");
            AvailXML x = new AvailXML(fileName, log);
            x.makeSS(outFile);
        } else if (optDumpSS) {
            if (optToXML | optToSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            message = "dumping file: " + fileName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            AvailSS.dumpFile(fileName);
        } else { // dumpSheet
            if (sheetName == null)
                throw new ParseException("sheet name not specified");
            message = "dumping file: " + fileName + " sheet: " + sheetName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            ss = new AvailSS(fileName, log, wx, clean);
            if (sheetNum < 0)
                as = ss.addSheet(sheetName);
            else
                as = ss.addSheet(sheetNum);

            ss.dumpSheet(sheetName);
        }
    } catch (ParseException exp) {
        System.out.println("bad command line: " + exp.getMessage());
        usage();
        System.exit(-1);
    }
}

From source file:com.epitech.oliver_f.astextexls.MainClass.java

public static void main(String[] args) {
    initalizeOption();//w w  w  . ja  v a2s  . c o m
    CommandLineParser parser = new BasicParser();
    CommandLine cl = null;
    try {
        cl = parser.parse(options, args);
    } catch (ParseException ex) {
        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (cl != null && cl.hasOption("help")) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("astexte script", options);
    }
    if (cl.hasOption("folder") && cl.hasOption("file")) {
        launchWriteAndRead(cl.getOptionValue("folder"), cl.getOptionValue("file"));
        System.out.println("OK");

    } else {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("astexte script", options);
    }
    launch(args);
}

From source file:com.evolveum.midpoint.tools.ninja.Main.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption(help);/*from ww  w  . ja  va2s .c  o m*/
    options.addOption(validate);
    options.addOption(create);
    options.addOption(importOp);
    options.addOption(schemaOp);
    options.addOption(exportOp);
    options.addOption(driver);
    options.addOption(url);
    options.addOption(username);
    options.addOption(password);
    options.addOption(Password);
    options.addOption(keyStore);
    options.addOption(trans);
    options.addOption(outputFormat);
    options.addOption(outputDirectory);
    options.addOption(input);

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine line = parser.parse(options, args);
        if (line.getOptions().length == 0 || line.hasOption(help.getOpt())) {
            printHelp(options);
            return;
        }

        //repository validation, if proper option is present
        boolean valid = validate(line, options);
        //import DDL, if proper option is present
        if (line.hasOption(create.getOpt())) {
            ImportDDL ddl = new ImportDDL(createDDLConfig(line));
            if (!ddl.execute()) {
                System.out.println("DLL import was unsuccessful, skipping other steps.");
                return;
            }

            //repository validation after DDL import, if proper option is present
            valid = validate(line, options);
        }

        //import objects, only if repository validation didn't fail (in case it was tested)
        if (valid && line.hasOption(importOp.getOpt())) {
            String path = line.getOptionValue(importOp.getOpt());
            boolean validateSchema = line.hasOption(schemaOp.getOpt());
            ImportObjects objects = new ImportObjects(path, validateSchema);
            objects.execute();
        }

        if (valid && line.hasOption(exportOp.getOpt())) {
            String path = line.getOptionValue(exportOp.getOpt());
            ExportObjects objects = new ExportObjects(path);
            objects.execute();
        }

        if (line.hasOption(keyStore.getOpt())) {
            KeyStoreDumper keyStoreDumper = new KeyStoreDumper();
            keyStoreDumper.execute();
        }

        if (line.hasOption(trans.getOpt())) {
            if (!checkCommand(line)) {
                return;
            }
            FileTransformer transformer = new FileTransformer();
            configureTransformer(transformer, line);
            transformer.execute();
        }
    } catch (ParseException ex) {
        System.out.println("Error: " + ex.getMessage());
        printHelp(options);
    } catch (Exception ex) {
        System.out.println("Exception occurred, reason: " + ex.getMessage());
        ex.printStackTrace();
    }
}

From source file:com.medsavant.mailer.Mail.java

public static void main(String[] args) throws IOException {
    CommandLineParser parser = new GnuParser();
    Options ops = getOptions();/*w  w w.j  av  a2s  .c  o  m*/
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(ops, args);

        // print help
        if (line.hasOption('h') || line.getOptions().length == 0) {
            printHelp();
            return;
        }

        // parse args

        String email = null;
        String emailPass = null;
        String mailingList = null;
        String subject = null;
        String htmlFile = null;

        for (Option o : line.getOptions()) {
            switch (o.getOpt().charAt(0)) {
            case 's':
                subject = o.getValue();
                break;
            case 'e':
                htmlFile = o.getValue();
                break;
            case 'u':
                email = o.getValue();
                break;
            case 'p':
                emailPass = o.getValue();
                break;
            case 'l':
                mailingList = o.getValue();
                break;
            }
        }

        setMailCredentials(email, emailPass, host, port);

        String text = readFileIntoString(new File(htmlFile));

        sendEmail(mailingList, subject, text);

    } catch (org.apache.commons.cli.ParseException exp) {

        printHelp();
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
    }
}

From source file:com.hortonworks.registries.storage.tool.TablesInitializer.java

public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(Option.builder("s").numberOfArgs(1).longOpt(OPTION_SCRIPT_ROOT_PATH)
            .desc("Root directory of script path").build());

    options.addOption(Option.builder("c").numberOfArgs(1).longOpt(OPTION_CONFIG_FILE_PATH)
            .desc("Config file path").build());

    options.addOption(Option.builder("m").numberOfArgs(1).longOpt(OPTION_MYSQL_JAR_URL_PATH)
            .desc("Mysql client jar url to download").build());

    options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_CREATE_TABLE)
            .desc("Execute 'create table' script").build());

    options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_DROP_TABLE)
            .desc("Execute 'drop table' script").build());

    options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_CHECK_CONNECTION)
            .desc("Check the connection for configured data source").build());

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);

    if (!commandLine.hasOption(OPTION_CONFIG_FILE_PATH) || !commandLine.hasOption(OPTION_SCRIPT_ROOT_PATH)) {
        usage(options);//from   w w w .  j a  v a2s  .  com
        System.exit(1);
    }

    // either create or drop should be specified, not both
    boolean executeCreate = commandLine.hasOption(OPTION_EXECUTE_CREATE_TABLE);
    boolean executeDrop = commandLine.hasOption(OPTION_EXECUTE_DROP_TABLE);
    boolean checkConnection = commandLine.hasOption(OPTION_EXECUTE_CHECK_CONNECTION);

    boolean moreThanOneOperationIsSpecified = executeCreate == executeDrop ? executeCreate : checkConnection;
    boolean noOperationSpecified = !(executeCreate || executeDrop || checkConnection);

    if (moreThanOneOperationIsSpecified) {
        System.out.println(
                "Only one operation can be execute at once, please select 'create' or 'drop', or 'check-connection'.");
        System.exit(1);
    } else if (noOperationSpecified) {
        System.out.println(
                "One of 'create', 'drop', 'check-connection' operation should be specified to execute.");
        System.exit(1);
    }

    String confFilePath = commandLine.getOptionValue(OPTION_CONFIG_FILE_PATH);
    String scriptRootPath = commandLine.getOptionValue(OPTION_SCRIPT_ROOT_PATH);
    String mysqlJarUrl = commandLine.getOptionValue(OPTION_MYSQL_JAR_URL_PATH);

    StorageProviderConfiguration storageProperties;
    try {
        Map<String, Object> conf = Utils.readConfig(confFilePath);

        StorageProviderConfigurationReader confReader = new StorageProviderConfigurationReader();
        storageProperties = confReader.readStorageConfig(conf);
    } catch (IOException e) {
        System.err.println("Error occurred while reading config file: " + confFilePath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    String bootstrapDirPath = null;
    try {
        bootstrapDirPath = System.getProperty("bootstrap.dir");
        MySqlDriverHelper.downloadMySQLJarIfNeeded(storageProperties, bootstrapDirPath, mysqlJarUrl);
    } catch (Exception e) {
        System.err.println("Error occurred while downloading MySQL jar. bootstrap dir: " + bootstrapDirPath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    try {
        SQLScriptRunner sqlScriptRunner = new SQLScriptRunner(storageProperties);

        try {
            sqlScriptRunner.initializeDriver();
        } catch (ClassNotFoundException e) {
            System.err.println(
                    "Driver class is not found in classpath. Please ensure that driver is in classpath.");
            System.exit(1);
        }

        if (checkConnection) {
            if (!sqlScriptRunner.checkConnection()) {
                System.exit(1);
            }
        } else if (executeDrop) {
            doExecuteDrop(sqlScriptRunner, storageProperties, scriptRootPath);
        } else {
            // executeCreate
            doExecuteCreate(sqlScriptRunner, storageProperties, scriptRootPath);
        }
    } catch (IOException e) {
        System.err.println("Error occurred while reading script file. Script root path: " + scriptRootPath);
        System.exit(1);
    }
}

From source file:ed.manager.Manager.java

public static void main(String args[]) throws Exception {

    HttpMonitor.setApplicationType("System Manager");

    Options o = new Options();
    o.addOption("v", "verbose", false, "Verbose");
    o.addOption("c", "config", true, "config file for TextConfigApplicationFactory");

    CommandLine cl = (new BasicParser()).parse(o, args);

    ApplicationFactory factory = null;/*from  ww  w. ja v  a 2 s  .c om*/
    if (cl.hasOption("config"))
        factory = new TextConfigApplicationFactory(new File(cl.getOptionValue("config", null)));
    else
        factory = new GridConfigApplicationFactory();

    Manager m = new Manager(factory, cl.hasOption("v"));
    m.start();
    m.join();
}

From source file:edu.cmu.lti.oaqa.knn4qa.apps.CollectionDiffer.java

public static void main(String[] args) {
    Options options = new Options();

    options.addOption("i1", null, true, "Input file 1");
    options.addOption("i2", null, true, "Input file 2");
    options.addOption("o", null, true, "Output file");

    CommandLineParser parser = new org.apache.commons.cli.GnuParser();

    try {//w w w  .  j  a va 2s.  c  o m
        CommandLine cmd = parser.parse(options, args);

        InputStream input1 = null, input2 = null;

        if (cmd.hasOption("i1")) {
            input1 = CompressUtils.createInputStream(cmd.getOptionValue("i1"));
        } else {
            Usage("Specify 'Input file 1'");
        }
        if (cmd.hasOption("i2")) {
            input2 = CompressUtils.createInputStream(cmd.getOptionValue("i2"));
        } else {
            Usage("Specify 'Input file 2'");
        }

        HashSet<String> hSubj = new HashSet<String>();

        BufferedWriter out = null;

        if (cmd.hasOption("o")) {
            String outFile = cmd.getOptionValue("o");

            out = new BufferedWriter(new OutputStreamWriter(CompressUtils.createOutputStream(outFile)));
        } else {
            Usage("Specify 'Output file'");
        }

        XmlIterator inpIter2 = new XmlIterator(input2, YahooAnswersReader.DOCUMENT_TAG);

        int docNum = 1;
        for (String oneRec = inpIter2.readNext(); !oneRec.isEmpty(); oneRec = inpIter2.readNext(), ++docNum) {
            if (docNum % 10000 == 0) {
                System.out.println(String.format(
                        "Loaded and memorized questions for %d documents from the second input file", docNum));
            }
            ParsedQuestion q = YahooAnswersParser.parse(oneRec, false);
            hSubj.add(q.mQuestion);
        }

        XmlIterator inpIter1 = new XmlIterator(input1, YahooAnswersReader.DOCUMENT_TAG);

        System.out.println("=============================================");
        System.out.println("Memoization is done... now let's diff!!!");
        System.out.println("=============================================");

        docNum = 1;
        int skipOverlapQty = 0, skipErrorQty = 0;
        for (String oneRec = inpIter1.readNext(); !oneRec.isEmpty(); ++docNum, oneRec = inpIter1.readNext()) {
            if (docNum % 10000 == 0) {
                System.out.println(String.format("Processed %d documents from the first input file", docNum));
            }

            oneRec = oneRec.trim() + System.getProperty("line.separator");

            ParsedQuestion q = null;
            try {
                q = YahooAnswersParser.parse(oneRec, false);
            } catch (Exception e) {
                // If <bestanswer>...</bestanswer> is missing we may end up here...
                // This is a bit funny, because this element is supposed to be mandatory,
                // but it's not.
                System.err.println("Skipping due to parsing error, exception: " + e);
                skipErrorQty++;
                continue;
            }
            if (hSubj.contains(q.mQuestion.trim())) {
                //System.out.println(String.format("Skipping uri='%s', question='%s'", q.mQuestUri, q.mQuestion));
                skipOverlapQty++;
                continue;
            }

            out.write(oneRec);
        }
        System.out.println(
                String.format("Processed %d documents, skipped because of overlap/errors %d/%d documents",
                        docNum - 1, skipOverlapQty, skipErrorQty));
        out.close();
    } catch (ParseException e) {
        Usage("Cannot parse arguments");
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Terminating due to an exception: " + e);
        System.exit(1);
    }
}

From source file:bs.java

public static void main(String[] args) throws FileNotFoundException {
    Options options = new Options();
    options.addOption(help);/*w w  w . j a va 2s .  co m*/
    options.addOption(version);
    options.addOption(loadPath);
    options.addOption(loadable);
    options.addOption(eval);

    //       args = new String[] { "Reflection.bs" };

    try {
        Bs.init();

        CommandLineParser argParser = new PosixParser();
        CommandLine line = argParser.parse(options, args);

        if (line.hasOption(HELP)) {
            help(options);
        }

        if (line.hasOption(VERSION)) {
            version();
        }

        if (line.hasOption(LOAD_PATH)) {
            loadPath(line.getOptionValue(LOAD_PATH));
        }

        if (line.hasOption(EVAL)) {
            eval(line.getOptionValue(EVAL));
        }

        if (line.hasOption(LOADABLE)) {
            loadable(line.getOptionValue(LOADABLE));
        }

        List<?> rest = line.getArgList();

        if (rest.size() > 0) {
            eval(rest);
        } else {
            repl();
        }

    } catch (ParseException e) {
        help(options);
    }

}