Example usage for org.apache.commons.cli ParseException getMessage

List of usage examples for org.apache.commons.cli ParseException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.cli ParseException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.cmu.sv.modelinference.runner.Main.java

public static void main(String[] args) {
    Options cmdOpts = createCmdOptions();

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;//from  w w  w .j a va 2  s.  c om
    try {
        cmd = parser.parse(cmdOpts, args, true);
    } catch (ParseException exp) {
        logger.error(exp.getMessage());
        System.err.println(exp.getMessage());
        Util.printHelpAndExit(Main.class, cmdOpts);
    }

    String inputType = cmd.getOptionValue(INPUT_TYPE_ARG);
    String tool = cmd.getOptionValue(TOOL_TYPE_ARG);
    String logFile = cmd.getOptionValue(LOG_FILE_ARG).replaceFirst("^~", System.getProperty("user.home"));

    LogHandler<?> logHandler = null;
    boolean found = false;
    for (LogHandler<?> lh : logHandlers) {
        if (lh.getHandlerName().equals(tool)) {
            logHandler = lh;
            found = true;
            break;
        }
    }
    if (!found) {
        StringBuilder sb = new StringBuilder();
        Iterator<LogHandler<?>> logIter = logHandlers.iterator();
        while (logIter.hasNext()) {
            sb.append(logIter.next().getHandlerName());
            if (logIter.hasNext())
                sb.append(", ");
        }
        logger.error("Did not find tool for arg " + tool);

        System.err.println("Supported tools: " + Util.getSupportedHandlersString(logHandlers));
        Util.printHelpAndExit(Main.class, cmdOpts);
    }
    logger.info("Using loghandler for logtype: " + logHandler.getHandlerName());

    logHandler.process(logFile, inputType, cmd.getArgs());
}

From source file:find.Main.java

public static void main(String[] args) throws Exception {
    Options options = getOptions();/*ww w.j  av  a2 s.c o  m*/
    try {

        CommandLineParser parser = new GnuParser();

        CommandLine line = parser.parse(options, args);
        File dir = new File(line.getOptionValue("dir", "."));
        String name = line.getOptionValue("name", "jar");
        Collection files = FindFile.find(dir, name);
        System.out.println("listing files in " + dir + " containing " + name);
        for (Iterator it = files.iterator(); it.hasNext();) {
            System.out.println("\t" + it.next() + "\n");
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("find", options);
    }
}

From source file:jlite.cli.ProxyDelegate.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();//ww w  .j ava  2  s .  co  m
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setSyntaxPrefix("Usage: ");
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
        if (line.hasOption("help")) {
            helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false);
            System.out.println(); // extra line
            System.exit(0);
        }
        if (line.hasOption("xml")) {
            System.out.println("<output>");
        }
        run(line);
    } catch (ParseException e) {
        System.err.println(e.getMessage() + "\n");
        helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false);
        System.out.println(); // extra line
        System.exit(-1);
    } catch (Exception e) {
        if ((line != null) && (line.hasOption("xml"))) {
            System.out.println("<error>" + e.getMessage() + "</error>");
        } else {
            System.err.println(e.getMessage());
        }
    } finally {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}

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(//www. j  a va2 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:edu.cuhk.hccl.cmd.AppQueryExpander.java

public static void main(String[] args) {

    try {/*from  ww  w.java  2  s  . c o  m*/

        CommandLineParser parser = new BasicParser();
        Options options = createOptions();
        CommandLine line = parser.parse(options, args);

        // Get parameters
        String queryStr = line.getOptionValue('q');
        int topK = Integer.parseInt(line.getOptionValue('k'));
        String modelPath = line.getOptionValue('m');
        String queryType = line.getOptionValue('t');

        QueryExpander expander = null;
        if (queryType.equalsIgnoreCase("WordVector")) {
            // Load word vectors
            System.out.println("[INFO] Loading word vectors...");
            expander = new WordVectorExpander(modelPath);
        } else if (queryType.equalsIgnoreCase("WordNet")) {
            // Load WordNet
            System.out.println("[INFO] Loading WordNet...");
            expander = new WordNetExpander(modelPath);
        } else {
            System.out.println("Please choose a correct expander: WordNet or WordVector!");
            System.exit(-1);
        }

        // Expand query
        System.out.println("[INFO] Computing similar words...");
        List<String> terms = expander.expandQuery(queryStr, topK);

        System.out.println(String.format("\n[INFO] The top %d similar words are: ", topK));
        for (String term : terms) {
            System.out.println(term);
        }

    } catch (ParseException exp) {
        System.out.println("Error in parameters: \n" + exp.getMessage());
        System.exit(-1);

    }
}

From source file:edu.usc.pgroup.floe.client.commands.Signal.java

/**
 * Entry point for Scale command.//from w w w.  java2s  . c om
 * @param args command line arguments sent by the floe.py script.
 */
public static void main(final String[] args) {

    Options options = new Options();

    Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Application Name").create("app");

    Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Pellet Name").create("pellet");

    Option signalOption = OptionBuilder.withArgName("data").hasArg().withType(new String())
            .withDescription("signal data to send to the pellet").create("data");

    options.addOption(appOption);
    options.addOption(pelletNameOption);
    options.addOption(signalOption);

    CommandLineParser parser = new BasicParser();
    CommandLine line;

    try {
        line = parser.parse(options, args);

    } catch (ParseException e) {
        LOGGER.error("Invalid command: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("scale options", options);
        return;
    }

    String app = line.getOptionValue("app");
    String pellet = line.getOptionValue("pellet");
    String data = line.getOptionValue("data");

    LOGGER.info("Application: {}", app);
    LOGGER.info("Pellet: {}", pellet);
    LOGGER.info("data: {}", data);

    byte[] datab = Utils.serialize(data);
    try {
        TSignal signal = new TSignal();
        signal.set_destApp(app);
        signal.set_destPellet(pellet);
        signal.set_data(datab);
        FloeClient.getInstance().getClient().signal(signal);
    } catch (TException e) {
        LOGGER.error("Error while connecting to the coordinator: {}", e);
    }
}

From source file:boa.BoaMain.java

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

    options.addOption("p", "parse", false, "parse and semantic check a Boa program (don't generate code)");
    options.addOption("c", "compile", false, "compile a Boa program");
    options.addOption("e", "execute", false, "execute a Boa program locally");
    options.addOption("g", "generate", false, "generate a Boa dataset");

    try {/*from  w  w  w.j a  va 2  s  .  c o  m*/
        if (args.length == 0) {
            printHelp(options, null);
            return;
        } else {
            final CommandLine cl = new PosixParser().parse(options, new String[] { args[0] });
            final String[] tempargs = new String[args.length - 1];
            System.arraycopy(args, 1, tempargs, 0, args.length - 1);

            if (cl.hasOption("c")) {
                boa.compiler.BoaCompiler.main(tempargs);
            } else if (cl.hasOption("p")) {
                boa.compiler.BoaCompiler.parseOnly(tempargs);
            } else if (cl.hasOption("e")) {
                boa.evaluator.BoaEvaluator.main(tempargs);
            } else if (cl.hasOption("g")) {
                boa.datagen.BoaGenerator.main(tempargs);
            }
        }
    } catch (final org.apache.commons.cli.ParseException e) {
        printHelp(options, e.getMessage());
    }
}

From source file:com.twitter.bazel.checkstyle.JavaCheckstyle.java

public static void main(String[] args) throws IOException {
    CommandLineParser parser = new DefaultParser();

    // create the Options
    Options options = new Options();
    options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file")
            .desc("bazel extra action protobuf file").build());
    options.addOption(Option.builder("c").required(true).hasArg().longOpt("checkstyle_config_file")
            .desc("checkstyle config file").build());

    try {/* ww  w . java 2 s . co  m*/
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        String extraActionFile = line.getOptionValue("f");
        String configFile = line.getOptionValue("c");

        String[] sourceFiles = getSourceFiles(extraActionFile);
        if (sourceFiles.length == 0) {
            LOG.fine("No java files found by checkstyle");
            return;
        }

        LOG.fine(sourceFiles.length + " java files found by checkstyle");

        String[] checkstyleArgs = (String[]) ArrayUtils.addAll(new String[] { "-c", configFile }, sourceFiles);

        LOG.fine("checkstyle args: " + Joiner.on(" ").join(checkstyleArgs));
        com.puppycrawl.tools.checkstyle.Main.main(checkstyleArgs);
    } catch (ParseException exp) {
        LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java " + CLASSNAME, options);
    }
}

From source file:edu.washington.data.sentimentreebank.StanfordNLPDict.java

public static void main(String args[]) {
    Options options = new Options();
    options.addOption("d", "dict", true, "dictionary file.");
    options.addOption("s", "sentiment", true, "sentiment value file.");

    CommandLineParser parser = new GnuParser();
    try {//  w ww. j  a  v a  2s  .  c  o m
        CommandLine line = parser.parse(options, args);
        if (!line.hasOption("dict") && !line.hasOption("sentiment")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("StanfordNLPDict", options);
            return;
        }

        Path dictPath = Paths.get(line.getOptionValue("dict"));
        Path sentimentPath = Paths.get(line.getOptionValue("sentiment"));

        StanfordNLPDict snlp = new StanfordNLPDict(dictPath, sentimentPath);
        String sentence = "take off";
        System.out.printf("sentence [%1$s] %2$s\n", sentence,
                String.valueOf(snlp.getPhraseSentiment(sentence)));

    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("StanfordNLPDict", options);
    } catch (IOException ex) {
        Logger.getLogger(StanfordNLPDict.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.usc.pgroup.floe.client.commands.Scale.java

/**
 * Entry point for Scale command.//w  ww  . j a va 2 s .c om
 * @param args command line arguments sent by the floe.py script.
 */
public static void main(final String[] args) {

    Options options = new Options();

    Option dirOption = OptionBuilder.withArgName("direction").hasArg().isRequired()
            .withDescription("Scale Direction.").create("dir");

    Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Application Name").create("app");

    Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Pellet Name").create("pellet");

    Option cntOption = OptionBuilder.withArgName("num").hasArg().withType(new String())
            .withDescription("Number of instances to scale up/down").create("cnt");

    options.addOption(dirOption);
    options.addOption(appOption);
    options.addOption(pelletNameOption);
    options.addOption(cntOption);

    CommandLineParser parser = new BasicParser();
    CommandLine line;

    try {
        line = parser.parse(options, args);

    } catch (ParseException e) {
        LOGGER.error("Invalid command: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("scale options", options);
        return;
    }

    String dir = line.getOptionValue("dir");
    String app = line.getOptionValue("app");
    String pellet = line.getOptionValue("pellet");
    String cnt = line.getOptionValue("cnt");

    LOGGER.info("direction: {}", dir);
    LOGGER.info("Application: {}", app);
    LOGGER.info("Pellet: {}", pellet);
    LOGGER.info("count: {}", cnt);

    ScaleDirection direction = Enum.valueOf(ScaleDirection.class, dir);
    int count = Integer.parseInt(cnt);
    try {
        FloeClient.getInstance().getClient().scale(direction, app, pellet, count);
    } catch (TException e) {
        LOGGER.error("Error while connecting to the coordinator: {}", e);
    }
}