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.ardoq.mavenImport.ArdoqMavenImport.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {

    Options options = initOptions();/*from  ww w.j  a v  a  2s  .  c  o  m*/

    CommandLine cmd;
    try {
        CommandLineParser parser = new BasicParser();
        cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            printHelp(options);
            return;
        }

        if (cmd.getArgList().isEmpty()) {
            System.out.println(
                    "One or more Maven artifact IDs required. For instance: 'io.dropwizard:dropwizard-core:0.8.1'");
            return;
        }

        String host = cmd.getOptionValue("h", "https://app.ardoq.com");
        String token = cmd.getOptionValue("t");
        String org = cmd.getOptionValue("o", "ardoq");
        String workspace = cmd.getOptionValue("w");
        List<String> importList = cmd.getArgList();

        ArdoqMavenImport ardoqMavenImport = new ArdoqMavenImport(host, workspace, org, token);
        MavenUtil mavenUtil = new MavenUtil(System.out, "test", "provided");

        if (cmd.hasOption("r")) {
            String extrarepo = cmd.getOptionValue("r");
            if (cmd.hasOption("u") && cmd.hasOption("p")) {
                String username = cmd.getOptionValue("u");
                String password = cmd.getOptionValue("p");
                mavenUtil.addRepository(extrarepo, username, password);
            } else {
                mavenUtil.addRepository(extrarepo);
            }
        }

        ardoqMavenImport.startImport(importList, mavenUtil);

    } catch (MissingOptionException moe) {
        printHelp(options);
    }
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.KratuMain.java

/**
 * Main method./*from   w  w  w . j a v a 2s  .c  o m*/
 *
 * @param args the command line arguments.
 */
public static void main(String args[]) {

    // Proxy
    JaxWsProxySelector ps = new JaxWsProxySelector(ProxySelector.getDefault());
    ProxySelector.setDefault(ps);

    Options options = createCommandLineOptions();

    boolean errors = false;
    String propertiesPath = CLASSPATH_AW_REPORT_MODEL_PROPERTIES_LOCATION;

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmdLine = parser.parse(options, args);

        if (cmdLine.hasOption("file")) {
            propertiesPath = cmdLine.getOptionValue("file");
        }
        System.out.println("Using properties from: " + propertiesPath);

        if (cmdLine.hasOption("startServer")) {
            // Start the Rest Server
            System.out.println("Starting Rest Server...");
            initApplicationContextAndProperties(propertiesPath);
            updateAccounts();

            RestServer.createRestServer(appCtx, propertiesPath);

        } else {
            if (cmdLine.hasOption("startDate") && cmdLine.hasOption("endDate")) {
                if (cmdLine.hasOption("processKratus")) {
                    // Process Kratus, this process runs for the whole MCC
                    // within the given dates and creates a daily Kratu per account.
                    System.out.println("Starting Process Kratus...");
                    initApplicationContextAndProperties(propertiesPath);
                    updateAccounts();

                    KratuProcessor kratuProcessor = appCtx.getBean(KratuProcessor.class);
                    kratuProcessor.processKratus(cmdLine.getOptionValue("startDate"),
                            cmdLine.getOptionValue("endDate"));
                    System.exit(0);

                } else {
                    // Download Reports,
                    // this porcess downloads 7 report types for each account under the MCC
                    System.out.println("Starting Download Reports porcess...");
                    AwReporting.main(args);
                    System.exit(0);

                }
            } else {
                errors = true;
                System.out.println("Configuration incomplete. Missing options for command line.");
            }
        }
    } catch (IOException e) {
        errors = true;
        System.out.println("Properties file (" + propertiesPath + ") not found: " + e.getMessage());
    } catch (ParseException e) {
        errors = true;
        System.out.println("Error parsing the values for the command line options: " + e.getMessage());
    } catch (Exception e) {
        errors = true;
        System.out.println("Unexpected error: " + e.getMessage());
    }

    if (errors) {
        printHelpMessage(options);
        System.exit(1);
    }
}

From source file:gr.demokritos.iit.demos.Demo.java

public static void main(String[] args) {
    try {//from  ww  w.ja va2 s. com
        Options options = new Options();
        options.addOption("h", HELP, false, "show help.");
        options.addOption("i", INPUT, true,
                "The file containing JSON " + " representations of tweets or SAG posts - 1 per line"
                        + " default file looked for is " + DEFAULT_INFILE);
        options.addOption("o", OUTPUT, true,
                "Where to write the output " + " default file looked for is " + DEFAULT_OUTFILE);
        options.addOption("p", PROCESS, true, "Type of processing to do "
                + " ner for Named Entity Recognition re for Relation Extraction" + " default is NER");
        options.addOption("s", SAG, false,
                "Whether to process as SAG posts" + " default is off - if passed means process as SAG posts");

        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);
        // DEFAULTS
        String filename = DEFAULT_INFILE;
        String outfilename = DEFAULT_OUTFILE;
        String process = NER;
        boolean isSAG = false;

        if (cmd.hasOption(HELP)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("NER + RE extraction module", options);
            System.exit(0);
        }
        if (cmd.hasOption(INPUT)) {
            filename = cmd.getOptionValue(INPUT);
        }
        if (cmd.hasOption(OUTPUT)) {
            outfilename = cmd.getOptionValue(OUTPUT);
        }
        if (cmd.hasOption(SAG)) {
            isSAG = true;
        }
        if (cmd.hasOption(PROCESS)) {
            process = cmd.getOptionValue(PROCESS);
        }
        System.out.println();
        System.out.println("Reading from file: " + filename);
        System.out.println("Process type: " + process);
        System.out.println("Processing SAG: " + isSAG);
        System.out.println("Writing to file: " + outfilename);
        System.out.println();

        List<String> jsoni = new ArrayList();
        Scanner in = new Scanner(new FileReader(filename));
        while (in.hasNextLine()) {
            String json = in.nextLine();
            jsoni.add(json);
        }
        PrintWriter writer = new PrintWriter(outfilename, "UTF-8");
        System.out.println("Read " + jsoni.size() + " lines from " + filename);
        if (process.equalsIgnoreCase(RE)) {
            System.out.println("Running Relation Extraction");
            System.out.println();
            String json = API.RE(jsoni, isSAG);
            System.out.println(json);
            writer.print(json);
        } else {
            System.out.println("Running Named Entity Recognition");
            System.out.println();
            jsoni = API.NER(jsoni, isSAG);
            /*
            for(String json: jsoni){
               NamedEntityList nel = NamedEntityList.fromJSON(json);
               nel.prettyPrint();
            }
            */
            for (String json : jsoni) {
                System.out.println(json);
                writer.print(json);
            }
        }
        writer.close();
    } catch (ParseException | UnsupportedEncodingException | FileNotFoundException ex) {
        Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:cc.wikitools.lucene.ScoreWikipediaArticle.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(//from  ww w .  j  a v a 2  s. co m
            OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("article id").create(ID_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("query text").create(QUERY_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(ID_OPTION) || cmdline.hasOption(TITLE_OPTION)) || !cmdline.hasOption(INDEX_OPTION)
            || !cmdline.hasOption(QUERY_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ScoreWikipediaArticle.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 queryText = cmdline.getOptionValue(QUERY_OPTION);

    WikipediaSearcher searcher = new WikipediaSearcher(indexLocation);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    if (cmdline.hasOption(ID_OPTION)) {
        out.println("score: "
                + searcher.scoreArticle(queryText, Integer.parseInt(cmdline.getOptionValue(ID_OPTION))));
    } else {
        out.println("score: " + searcher.scoreArticle(queryText, cmdline.getOptionValue(TITLE_OPTION)));
    }

    searcher.close();
    out.close();
}

From source file:de.onyxbits.raccoon.cli.Router.java

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

    Option property = Option.builder("D").argName("property=value").numberOfArgs(2).valueSeparator()
            .desc(Messages.getString(DESC + "D")).build();
    options.addOption(property);//ww w .ja va2 s .  co  m

    Option help = new Option("h", "help", false, Messages.getString(DESC + "h"));
    options.addOption(help);

    Option version = new Option("v", "version", false, Messages.getString(DESC + "v"));
    options.addOption(version);

    // GPA: Google Play Apps (we might add different markets later)
    Option playAppDetails = new Option(null, "gpa-details", true, Messages.getString(DESC + "gpa-details"));
    playAppDetails.setArgName("package");
    options.addOption(playAppDetails);

    Option playAppBulkDetails = new Option(null, "gpa-bulkdetails", true,
            Messages.getString(DESC + "gpa-bulkdetails"));
    playAppBulkDetails.setArgName("file");
    options.addOption(playAppBulkDetails);

    Option playAppBatchDetails = new Option(null, "gpa-batchdetails", true,
            Messages.getString(DESC + "gpa-batchdetails"));
    playAppBatchDetails.setArgName("file");
    options.addOption(playAppBatchDetails);

    Option playAppSearch = new Option(null, "gpa-search", true, Messages.getString(DESC + "gpa-search"));
    playAppSearch.setArgName("query");
    options.addOption(playAppSearch);

    CommandLine commandLine = null;
    try {
        commandLine = new DefaultParser().parse(options, args);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }

    if (commandLine.hasOption(property.getOpt())) {
        System.getProperties().putAll(commandLine.getOptionProperties(property.getOpt()));
    }

    if (commandLine.hasOption(help.getOpt())) {
        new HelpFormatter().printHelp("raccoon", Messages.getString("header"), options,
                Messages.getString("footer"), true);
        System.exit(0);
    }

    if (commandLine.hasOption(version.getOpt())) {
        System.out.println(GlobalsProvider.getGlobals().get(Version.class));
        System.exit(0);
    }

    if (commandLine.hasOption(playAppDetails.getLongOpt())) {
        Play.details(commandLine.getOptionValue(playAppDetails.getLongOpt()));
        System.exit(0);
    }

    if (commandLine.hasOption(playAppBulkDetails.getLongOpt())) {
        Play.bulkDetails(new File(commandLine.getOptionValue(playAppBulkDetails.getLongOpt())));
        System.exit(0);
    }

    if (commandLine.hasOption(playAppBatchDetails.getLongOpt())) {
        Play.details(new File(commandLine.getOptionValue(playAppBatchDetails.getLongOpt())));
        System.exit(0);
    }

    if (commandLine.hasOption(playAppSearch.getLongOpt())) {
        Play.search(commandLine.getOptionValue(playAppSearch.getLongOpt()));
        System.exit(0);
    }
}

From source file:net.ladenthin.snowman.imager.run.CLI.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    try {/*from w  w  w  . ja v  a2s. c  o m*/
        CommandLineParser parser = new PosixParser();
        Options options = new Options();

        options.addOption(cmdHelpS, cmdHelp, false, cmdHelpD);
        options.addOption(cmdVersionS, cmdVersion, false, cmdVersionD);

        options.addOption(OptionBuilder.withDescription(cmdConfigurationD).withLongOpt(cmdConfiguration)
                .hasArg().withArgName(cmdConfigurationA).create(cmdConfigurationS));

        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        final String cmdLineSyntax = "java -jar " + Imager.jarFilename;
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();

        final String configurationPath;
        if (line.hasOption(cmdConfiguration)) {
            configurationPath = line.getOptionValue(cmdConfiguration);
        } else {
            System.out.println("Need configuration value.");
            formatter.printHelp(cmdLineSyntax, options);
            return;
        }

        // check parameter
        if (args.length == 0 || line.hasOption(cmdHelp)) {
            formatter.printHelp(cmdLineSyntax, options);
            return;
        }

        if (line.hasOption(cmdVersion)) {
            System.out.println(Imager.version);
            return;
        }

        Imager imager = new Imager(configurationPath);
        imager.waitForAllThreads();
        imager.restartAndExit();

    } catch (IllegalArgumentException | ParseException | IOException | InstantiationException
            | InterruptedException e) {
        LOGGER.error("Critical exception.", e);
        System.exit(-1);
    }
}

From source file:com.genentech.struchk.OEMDLPercieveChecker.java

public static void main(String[] args) throws ParseException, JDOMException, IOException {
    // 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  . java 2  s  . c  om
    options.addOption(opt);

    opt = new Option("o", true, "output file");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("d", false, "debug: wait for user to press key at startup.");
    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 inFile = cmd.getOptionValue("i");
    String outFile = cmd.getOptionValue("o");

    OEMDLPercieveChecker checker = null;
    try {
        checker = new OEMDLPercieveChecker();

        oemolostream out = new oemolostream(outFile);
        oemolistream in = new oemolistream(inFile);

        OEGraphMol mol = new OEGraphMol();
        while (oechem.OEReadMolecule(in, mol)) {
            if (!checker.checkMol(mol))
                oechem.OEWriteMolecule(out, mol);
        }
        checker.delete();
        in.close();
        in.delete();

        out.close();
        out.delete();

    } catch (Exception e) {
        throw new Error(e);
    }
    System.err.println("Done:");
}

From source file:com.pinterest.secor.main.LogFileVerifierMain.java

public static void main(String[] args) {
    try {/* w w w.  j ava  2s .co  m*/
        CommandLine commandLine = parseArgs(args);
        SecorConfig config = SecorConfig.load();
        FileUtil.configure(config);
        LogFileVerifier verifier = new LogFileVerifier(config, commandLine.getOptionValue("topic"));
        long startOffset = -2;
        long endOffset = Long.MAX_VALUE;
        if (commandLine.hasOption("start_offset")) {
            startOffset = Long.parseLong(commandLine.getOptionValue("start_offset"));
            if (commandLine.hasOption("end_offset")) {
                endOffset = Long.parseLong(commandLine.getOptionValue("end_offset"));
            }
        }
        int numMessages = -1;
        if (commandLine.hasOption("messages")) {
            numMessages = ((Number) commandLine.getParsedOptionValue("messages")).intValue();
        }
        verifier.verifyCounts(startOffset, endOffset, numMessages);
        if (commandLine.hasOption("sequence_offsets")) {
            verifier.verifySequences(startOffset, endOffset);
        }
        System.out.println("verification succeeded");
    } catch (Throwable t) {
        LOG.error("Log file verifier failed", t);
        System.exit(1);
    }
}

From source file:jeplus.util.LineEnds.java

public static void main(String[] args) {

    String LN = "\r\n";

    // create the parser
    CommandLineParser parser = new GnuParser();
    Options options = getCommandLineOptions();
    CommandLine commandline = null;
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(80);//from ww  w. j  ava  2  s  .  c om
    try {
        // parse the command line arguments
        commandline = parser.parse(options, args);
        if (commandline.hasOption("help")) {
            // automatically generate the help statement
            formatter.printHelp("java -cp jEPlusNet.jar jeplusplus.util.LineEnds [OPTIONS]", options);
            System.exit(-1);
        }
        // Set log4j configuration
        if (commandline.hasOption("log")) {
            PropertyConfigurator.configure(commandline.getOptionValue("log"));
        } else {
            PropertyConfigurator.configure("log4j.cfg");
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        // automatically generate the help statement
        formatter.printHelp("java -Xmx500m -jar JESS_Client.jar [OPTIONS]", options);
        System.exit(-1);
    }

    if (commandline.hasOption("style")) {
        if (commandline.getOptionValue("style").startsWith("L")) {
            LN = "\n";
        }
    }

    if (commandline.hasOption("file")) {
        File file = new File(commandline.getOptionValue("file"));
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] listOfFiles = file.listFiles();
                for (int i = 0; i < listOfFiles.length; i++) {
                    if (listOfFiles[i].isFile()) {
                        convertFile(listOfFiles[i], LN);
                    }
                }
            } else {
                convertFile(file, LN);
            }
        }
    }
}

From source file:com.aestel.chemistry.openEye.fp.apps.SDFFPSphereExclusion.java

public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file [.sdf,...]");
    opt.setRequired(true);//  w w  w . j  a  v  a2 s  .  co  m
    options.addOption(opt);

    opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("ref", true, "refrence file to be loaded before starting");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("fpTag", true, "field containing fingerpPrint");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("maxTanimoto", false,
            "If given the modified maxTanimoto will be used = common/(2*Max(na,nb)-common).");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("radius", true, "radius of exclusion sphere, exclude anything with similarity >= radius.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("printSphereMatchCount", false,
            "check and print membership of candidates not "
                    + " only to the first centroid which has sim >= radius but to all centroids"
                    + " found up to that input. This will output a candidate multiple times."
                    + " Implies checkSpheresInOrder.");
    options.addOption(opt);

    opt = new Option("checkSpheresInOrder", false,
            "For each candiate: compare to centroids from first to last (default is last to first)");
    options.addOption(opt);

    opt = new Option("printAll", false, "print all molecule, check includeIdx tag");
    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();
    }

    // the only reason not to match centroids in reverse order id if
    // a non-centroid is to be assigned to multiple centroids
    boolean printSphereMatchCount = cmd.hasOption("printSphereMatchCount");
    boolean reverseMatch = !cmd.hasOption("checkSpheresInOrder") && !printSphereMatchCount;
    boolean printAll = cmd.hasOption("printAll") || printSphereMatchCount;
    boolean doMaxTanimoto = cmd.hasOption("maxTanimoto");
    String fpTag = cmd.getOptionValue("fpTag");
    double radius = Double.parseDouble(cmd.getOptionValue("radius"));
    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String refFile = cmd.getOptionValue("ref");

    SimComparatorFactory<OEMolBase, FPComparator, FPComparator> compFact = new FPComparatorFact(doMaxTanimoto,
            fpTag);
    SphereExclusion<FPComparator, FPComparator> alg = new SphereExclusion<FPComparator, FPComparator>(compFact,
            refFile, outFile, radius, reverseMatch, printSphereMatchCount, printAll);
    alg.run(inFile);
    alg.close();
}