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:com.boozallen.cognition.kom.KafakOffsetMonitor.java

public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;/*from ww  w  . ja v  a  2 s.c  om*/
    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:de.l3s.content.mapred.WikipediaPagesBz2InputStream.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("gzipped XML dump file")
            .create(INPUT_OPTION));//from www. ja v  a 2 s.c  o  m
    options.addOption(OptionBuilder.withArgName("lang").hasArg().withDescription("output location")
            .create(LANGUAGE_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(INPUT_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(WikipediaPagesBz2InputStream.class.getCanonicalName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String path = cmdline.getOptionValue(INPUT_OPTION);
    String lang = cmdline.hasOption(LANGUAGE_OPTION) ? cmdline.getOptionValue(LANGUAGE_OPTION) : "en";
    WikipediaPage p = WikipediaPageFactory.createWikipediaPage(lang);

    WikipediaPagesBz2InputStream stream = new WikipediaPagesBz2InputStream(path);
    while (stream.readNext(p)) {
        System.out.println(p.getTitle() + "\t" + p.getDocid());
    }
}

From source file:cc.twittertools.util.ExtractSubcollection.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory")
            .create(COLLECTION_OPTION));
    options.addOption(//www  .j a  va2s .co m
            OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_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(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ExtractSubcollection.class.getName(), options);
        System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    LongOpenHashSet tweetids = new LongOpenHashSet();
    File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION));
    if (!tweetidsFile.exists()) {
        System.err.println("Error: " + tweetidsFile + " does not exist!");
        System.exit(-1);
    }
    LOG.info("Reading tweetids from " + tweetidsFile);

    FileInputStream fin = new FileInputStream(tweetidsFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(fin));

    String s;
    while ((s = br.readLine()) != null) {
        tweetids.add(Long.parseLong(s));
    }
    br.close();
    fin.close();
    LOG.info("Read " + tweetids.size() + " tweetids.");

    File file = new File(collectionPath);
    if (!file.exists()) {
        System.err.println("Error: " + file + " does not exist!");
        System.exit(-1);
    }

    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    StatusStream stream = new JsonStatusCorpusReader(file);
    Status status;
    while ((status = stream.next()) != null) {
        if (tweetids.contains(status.getId())) {
            out.println(status.getJsonObject().toString());
        }
    }
    stream.close();
    out.close();
}

From source file:com.twitter.bazel.checkstyle.PythonCheckstyle.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("p").required(true).hasArg().longOpt("pylint_file")
            .desc("Executable pylint file to invoke").build());

    try {//www  .j a  v  a2 s . c o  m
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        String extraActionFile = line.getOptionValue("f");
        String pylintFile = line.getOptionValue("p");

        Collection<String> sourceFiles = getSourceFiles(extraActionFile);
        if (sourceFiles.size() == 0) {
            LOG.info("No python files found by checkstyle");
            return;
        }

        LOG.info(sourceFiles.size() + " python files found by checkstyle");

        // Create and run the command
        List<String> commandBuilder = new ArrayList<>();
        commandBuilder.add(pylintFile);
        commandBuilder.addAll(sourceFiles);
        runLinter(commandBuilder);

    } 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: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);/*from  ww  w. j ava  2s .  c om*/

    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:cd.what.DutchBot.Main.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException, IrcException, InterruptedException,
        ConfigurationException, InstantiationException, IllegalAccessException {
    String configfile = "irc.properties";
    DutchBot bot = null;//from w w  w  .  ja  va2 s .  c o  m

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("config").withArgName("configfile").hasArg()
            .withDescription("Load configuration from configfile, or use the default irc.cfg").create("c"));
    options.addOption(OptionBuilder.withLongOpt("server").withArgName("<url>").hasArg()
            .withDescription("Connect to this server").create("s"));
    options.addOption(OptionBuilder.withLongOpt("port").hasArg().withArgName("port")
            .withDescription("Connect to the server with this port").create("p"));
    options.addOption(OptionBuilder.withLongOpt("password").hasArg().withArgName("password")
            .withDescription("Connect to the server with this password").create("pw"));
    options.addOption(OptionBuilder.withLongOpt("nick").hasArg().withArgName("nickname")
            .withDescription("Connect to the server with this nickname").create("n"));
    options.addOption(OptionBuilder.withLongOpt("nspass").hasArg().withArgName("password")
            .withDescription("Sets the password for NickServ").create("ns"));
    options.addOption("h", "help", false, "Displays this menu");

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cli = parser.parse(options, args);
        if (cli.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("DutchBot", options);
            return;
        }
        // check for override config file
        if (cli.hasOption("c"))
            configfile = cli.getOptionValue("c");

        bot = new DutchBot(configfile);

        // Read the cli parameters
        if (cli.hasOption("pw"))
            bot.setServerPassword(cli.getOptionValue("pw"));
        if (cli.hasOption("s"))
            bot.setServerAddress(cli.getOptionValue("s"));
        if (cli.hasOption("p"))
            bot.setIrcPort(Integer.parseInt(cli.getOptionValue("p")));
        if (cli.hasOption("n"))
            bot.setBotName(cli.getOptionValue("n"));
        if (cli.hasOption("ns"))
            bot.setNickservPassword(cli.getOptionValue("ns"));

    } catch (ParseException e) {
        System.err.println("Error parsing command line vars " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("DutchBot", options);
        System.exit(1);
    }

    boolean result = bot.tryConnect();

    if (result)
        bot.logMessage("Connected");
    else {
        System.out.println(" Connecting failed :O");
        System.exit(1);
    }
}

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());/* ww w .  j  av  a2 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:edu.usc.pgroup.floe.flake.FlakeService.java

/**
 * Entry point for the flake.//from  w w  w. j av  a 2s  .  c o m
 *
 * @param args commandline arguments. (TODO)
 */
public static void main(final String[] args) {

    Options options = buildOptions();

    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("FlakeService", options);
        return;
    }

    String pid = line.getOptionValue("pid");
    String id = line.getOptionValue("id");
    String cid = line.getOptionValue("cid");
    String appName = line.getOptionValue("appname");
    String token = line.getOptionValue("token");
    String jar = null;
    if (line.hasOption("jar")) {
        jar = line.getOptionValue("jar");
    }

    LOGGER.info("pid: {}, id:{}, cid:{}, app:{}, jar:{}", pid, id, cid, appName, jar);
    try {
        new FlakeService(pid, id, cid, appName, jar).start();
    } catch (Exception e) {
        LOGGER.error("Exception while creating flake: {}", e);
        return;
    }
}

From source file:jlite.cli.ProxyInfo.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();//from w ww.  ja v a  2  s. com
    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 + "\n", 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 + "\n", false);
        System.out.println(); // extra line
        System.exit(-1);
    } catch (Exception e) {
        if (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:com.subakva.formicid.Main.java

public static void main(final String[] args) {
    Options options = new Options();
    options.addOption("p", "projecthelp", false, "print project help information");
    options.addOption("f", "file", true, "use given buildfile");
    options.addOption("h", "help", false, "print this message");
    options.addOption("d", "debug", false, "print debugging information");
    options.addOption("v", "verbose", false, "be extra verbose");
    options.addOption("q", "quiet", false, "be extra quiet");

    CommandLine cli;/*  w  ww.j  av  a2  s  .  co  m*/
    try {
        cli = new GnuParser().parse(options, args);
    } catch (ParseException e) {
        System.out.println("Error: " + e.getMessage());
        new HelpFormatter().printHelp(CLI_SYNTAX, options);
        return;
    }

    String scriptName = cli.getOptionValue("f", "build.js");
    if (cli.hasOption("h")) {
        new HelpFormatter().printHelp(CLI_SYNTAX, options);
        return;
    } else if (cli.hasOption("p")) {
        runScript(scriptName, "projecthelp", null);
    } else {
        runScript(scriptName, "build", cli);
    }
}