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:cc.wikitools.lucene.IndexWikipediaDump.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("bz2 Wikipedia XML dump file")
            .create(INPUT_OPTION));//w  ww . j  a  v a 2s .  c o  m
    options.addOption(
            OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg()
            .withDescription("maximum number of documents to index").create(MAX_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of indexing threads")
            .create(THREADS_OPTION));

    options.addOption(new Option(OPTIMIZE_OPTION, "merge indexes into a single segment"));

    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) || !cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(IndexWikipediaDump.class.getCanonicalName(), options);
        System.exit(-1);
    }

    String indexPath = cmdline.getOptionValue(INDEX_OPTION);
    int maxdocs = cmdline.hasOption(MAX_OPTION) ? Integer.parseInt(cmdline.getOptionValue(MAX_OPTION))
            : Integer.MAX_VALUE;
    int threads = cmdline.hasOption(THREADS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(THREADS_OPTION))
            : DEFAULT_NUM_THREADS;

    long startTime = System.currentTimeMillis();

    String path = cmdline.getOptionValue(INPUT_OPTION);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    WikiClean cleaner = new WikiCleanBuilder().withTitle(true).build();

    Directory dir = FSDirectory.open(new File(indexPath));
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, ANALYZER);
    config.setOpenMode(OpenMode.CREATE);

    IndexWriter writer = new IndexWriter(dir, config);
    LOG.info("Creating index at " + indexPath);
    LOG.info("Indexing with " + threads + " threads");

    try {
        WikipediaBz2DumpInputStream stream = new WikipediaBz2DumpInputStream(path);

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        int cnt = 0;
        String page;
        while ((page = stream.readNext()) != null) {
            String title = cleaner.getTitle(page);

            // These are heuristic specifically for filtering out non-articles in enwiki-20120104.
            if (title.startsWith("Wikipedia:") || title.startsWith("Portal:") || title.startsWith("File:")) {
                continue;
            }

            if (page.contains("#REDIRECT") || page.contains("#redirect") || page.contains("#Redirect")) {
                continue;
            }

            Runnable worker = new AddDocumentRunnable(writer, cleaner, page);
            executor.execute(worker);

            cnt++;
            if (cnt % 10000 == 0) {
                LOG.info(cnt + " articles added");
            }
            if (cnt >= maxdocs) {
                break;
            }
        }

        executor.shutdown();
        // Wait until all threads are finish
        while (!executor.isTerminated()) {
        }

        LOG.info("Total of " + cnt + " articles indexed.");

        if (cmdline.hasOption(OPTIMIZE_OPTION)) {
            LOG.info("Merging segments...");
            writer.forceMerge(1);
            LOG.info("Done!");
        }

        LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        writer.close();
        dir.close();
        out.close();
    }
}

From source file:com.fatwire.dta.sscrawler.App.java

/**
 * @param args//from   w  ww  .  ja  va2  s.c  o m
 * @throws Exception
 */
public static void main(final String[] args) throws Exception {

    if (args.length < 1) {
        printUsage();
        System.exit(1);
    }
    DOMConfigurator.configure("conf/log4j.xml");
    final Options o = App.setUpCmd();
    final CommandLineParser p = new BasicParser();
    try {
        final CommandLine s = p.parse(o, args);
        if (s.hasOption('h')) {
            printUsage();
        } else if (s.getArgList().contains("crawler") && s.getArgList().size() > 1) {
            new App().doWork(s);
        } else if (s.getArgList().contains("warmer") && s.getArgList().size() > 1) {
            new CacheWarmer().doWork(s);
        } else {
            System.err.println("no subcommand and/or URI found on " + s.getArgList());
            printUsage();
            System.exit(1);
        }

    } catch (final ParseException e) {
        System.err.println(e.getMessage());
        printUsage();
        System.exit(1);
    }

}

From source file:de.topobyte.livecg.ShowVisualization.java

public static void main(String[] args) {
    EnumNameLookup<Visualization> visualizationSwitch = new EnumNameLookup<Visualization>(Visualization.class,
            true);//from   w w  w.  j  a va  2s  .c o m

    // @formatter:off
    Options options = new Options();
    OptionHelper.add(options, OPTION_CONFIG, true, false, "path", "config file");
    OptionHelper.add(options, OPTION_VISUALIZATION, true, true, "type",
            "type of visualization. one of <" + VisualizationUtil.getListOfAvailableVisualizations() + ">");
    OptionHelper.add(options, OPTION_STATUS, true, false,
            "status to " + "set the algorithm to. The format depends on the algorithm");
    // @formatter:on

    Option propertyOption = new Option(OPTION_PROPERTIES, "set a special property");
    propertyOption.setArgName("property=value");
    propertyOption.setArgs(2);
    propertyOption.setValueSeparator('=');
    options.addOption(propertyOption);

    CommandLineParser clp = new GnuParser();

    CommandLine line = null;
    try {
        line = clp.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parsing command line failed: " + e.getMessage());
        new HelpFormatter().printHelp(HELP_MESSAGE, options);
        System.exit(1);
    }

    String[] extra = line.getArgs();
    if (extra.length == 0) {
        System.out.println("Missing file argument");
        new HelpFormatter().printHelp(HELP_MESSAGE, options);
        System.exit(1);
    }
    String input = extra[0];

    StringOption argConfig = ArgumentHelper.getString(line, OPTION_CONFIG);
    if (argConfig.hasValue()) {
        String configPath = argConfig.getValue();
        LiveConfig.setPath(configPath);
    }

    StringOption argVisualization = ArgumentHelper.getString(line, OPTION_VISUALIZATION);
    StringOption argStatus = ArgumentHelper.getString(line, OPTION_STATUS);

    Visualization visualization = visualizationSwitch.find(argVisualization.getValue());
    if (visualization == null) {
        System.err.println("Unsupported visualization '" + argVisualization.getValue() + "'");
        System.exit(1);
    }

    System.out.println("Visualization: " + visualization);

    ContentReader contentReader = new ContentReader();
    Content content = null;
    try {
        content = contentReader.read(new File(input));
    } catch (Exception e) {
        System.out.println("Error while reading input file '" + input + "'. Exception type: "
                + e.getClass().getSimpleName() + ", message: " + e.getMessage());
        System.exit(1);
    }

    Properties properties = line.getOptionProperties(OPTION_PROPERTIES);

    ContentLauncher launcher = null;

    switch (visualization) {
    case GEOMETRY: {
        launcher = new ContentDisplayLauncher();
        break;
    }
    case DCEL: {
        launcher = new DcelLauncher();
        break;
    }
    case FREESPACE: {
        launcher = new FreeSpaceChainsLauncher();
        break;
    }
    case DISTANCETERRAIN: {
        launcher = new DistanceTerrainChainsLauncher();
        break;
    }
    case CHAN: {
        launcher = new ChanLauncher();
        break;
    }
    case FORTUNE: {
        launcher = new FortunesSweepLauncher();
        break;
    }
    case MONOTONE_PIECES: {
        launcher = new MonotonePiecesLauncher();
        break;
    }
    case MONOTONE_TRIANGULATION: {
        launcher = new MonotoneTriangulationLauncher();
        break;
    }
    case TRIANGULATION: {
        launcher = new MonotonePiecesTriangulationLauncher();
        break;
    }
    case SPIP: {
        launcher = new ShortestPathInPolygonLauncher();
        break;
    }
    case BUFFER: {
        launcher = new PolygonBufferLauncher();
        break;
    }
    }

    try {
        launcher.launch(content, true);
    } catch (LaunchException e) {
        System.err.println("Unable to start visualization");
        System.err.println("Error message: " + e.getMessage());
        System.exit(1);
    }
}

From source file:de.topobyte.osm4j.pbf.executables.EntitySplit.java

public static void main(String[] args) throws IOException {
    // @formatter:off
    Options options = new Options();
    OptionHelper.add(options, OPTION_INPUT, true, false, "input file");
    OptionHelper.add(options, OPTION_OUTPUT_NODES, true, false, "the file to write nodes to");
    OptionHelper.add(options, OPTION_OUTPUT_WAYS, true, false, "the file to write ways to");
    OptionHelper.add(options, OPTION_OUTPUT_RELATIONS, true, false, "the file to write relations to");
    // @formatter:on

    CommandLine line = null;//from   w  w  w .  ja  v  a 2  s .com
    try {
        line = new GnuParser().parse(options, args);
    } catch (ParseException e) {
        System.out.println("unable to parse command line: " + e.getMessage());
        new HelpFormatter().printHelp(HELP_MESSAGE, options);
        System.exit(1);
    }

    if (line == null) {
        return;
    }

    InputStream in = null;
    if (line.hasOption(OPTION_INPUT)) {
        String inputPath = line.getOptionValue(OPTION_INPUT);
        File file = new File(inputPath);
        FileInputStream fis = new FileInputStream(file);
        in = new BufferedInputStream(fis);
    } else {
        in = new BufferedInputStream(System.in);
    }

    OutputStream outNodes = null, outWays = null, outRelations = null;
    if (line.hasOption(OPTION_OUTPUT_NODES)) {
        String path = line.getOptionValue(OPTION_OUTPUT_NODES);
        FileOutputStream fos = new FileOutputStream(path);
        outNodes = new BufferedOutputStream(fos);
    }
    if (line.hasOption(OPTION_OUTPUT_WAYS)) {
        String path = line.getOptionValue(OPTION_OUTPUT_WAYS);
        FileOutputStream fos = new FileOutputStream(path);
        outWays = new BufferedOutputStream(fos);
    }
    if (line.hasOption(OPTION_OUTPUT_RELATIONS)) {
        String path = line.getOptionValue(OPTION_OUTPUT_RELATIONS);
        FileOutputStream fos = new FileOutputStream(path);
        outRelations = new BufferedOutputStream(fos);
    }

    if (outNodes == null && outWays == null && outRelations == null) {
        System.out.println("You should specify an output for at least one entity");
        System.exit(1);
    }

    EntitySplit task = new EntitySplit(in, outNodes, outWays, outRelations);
    task.execute();
}

From source file:io.druid.examples.rabbitmq.RabbitMQProducerMain.java

public static void main(String[] args) throws Exception {
    // We use a List to keep track of option insertion order. See below.
    final List<Option> optionList = new ArrayList<Option>();

    optionList.add(OptionBuilder.withLongOpt("help").withDescription("display this help message").create("h"));
    optionList.add(OptionBuilder.withLongOpt("hostname").hasArg()
            .withDescription("the hostname of the AMQP broker [defaults to AMQP library default]").create("b"));
    optionList.add(OptionBuilder.withLongOpt("port").hasArg()
            .withDescription("the port of the AMQP broker [defaults to AMQP library default]").create("n"));
    optionList.add(OptionBuilder.withLongOpt("username").hasArg()
            .withDescription("username to connect to the AMQP broker [defaults to AMQP library default]")
            .create("u"));
    optionList.add(OptionBuilder.withLongOpt("password").hasArg()
            .withDescription("password to connect to the AMQP broker [defaults to AMQP library default]")
            .create("p"));
    optionList.add(OptionBuilder.withLongOpt("vhost").hasArg()
            .withDescription("name of virtual host on the AMQP broker [defaults to AMQP library default]")
            .create("v"));
    optionList.add(OptionBuilder.withLongOpt("exchange").isRequired().hasArg()
            .withDescription("name of the AMQP exchange [required - no default]").create("e"));
    optionList.add(OptionBuilder.withLongOpt("key").hasArg()
            .withDescription("the routing key to use when sending messages [default: 'default.routing.key']")
            .create("k"));
    optionList.add(OptionBuilder.withLongOpt("type").hasArg()
            .withDescription("the type of exchange to create [default: 'topic']").create("t"));
    optionList.add(OptionBuilder.withLongOpt("durable")
            .withDescription("if set, a durable exchange will be declared [default: not set]").create("d"));
    optionList.add(OptionBuilder.withLongOpt("autodelete")
            .withDescription("if set, an auto-delete exchange will be declared [default: not set]")
            .create("a"));
    optionList.add(OptionBuilder.withLongOpt("single")
            .withDescription("if set, only a single message will be sent [default: not set]").create("s"));
    optionList.add(OptionBuilder.withLongOpt("start").hasArg()
            .withDescription("time to use to start sending messages from [default: 2010-01-01T00:00:00]")
            .create());//  w  w w. j  a v a  2s.  c  o  m
    optionList.add(OptionBuilder.withLongOpt("stop").hasArg().withDescription(
            "time to use to send messages until (format: '2013-07-18T23:45:59') [default: current time]")
            .create());
    optionList.add(OptionBuilder.withLongOpt("interval").hasArg()
            .withDescription("the interval to add to the timestamp between messages in seconds [default: 10]")
            .create());
    optionList.add(OptionBuilder.withLongOpt("delay").hasArg()
            .withDescription("the delay between sending messages in milliseconds [default: 100]").create());

    // An extremely silly hack to maintain the above order in the help formatting.
    HelpFormatter formatter = new HelpFormatter();
    // Add a comparator to the HelpFormatter using the ArrayList above to sort by insertion order.
    formatter.setOptionComparator(new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            // I know this isn't fast, but who cares! The list is short.
            return optionList.indexOf(o1) - optionList.indexOf(o2);
        }
    });

    // Now we can add all the options to an Options instance. This is dumb!
    Options options = new Options();
    for (Option option : optionList) {
        options.addOption(option);
    }

    CommandLine cmd = null;

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

    } catch (ParseException e) {
        formatter.printHelp("RabbitMQProducerMain", e.getMessage(), options, null);
        System.exit(1);
    }

    if (cmd.hasOption("h")) {
        formatter.printHelp("RabbitMQProducerMain", options);
        System.exit(2);
    }

    ConnectionFactory factory = new ConnectionFactory();

    if (cmd.hasOption("b")) {
        factory.setHost(cmd.getOptionValue("b"));
    }
    if (cmd.hasOption("u")) {
        factory.setUsername(cmd.getOptionValue("u"));
    }
    if (cmd.hasOption("p")) {
        factory.setPassword(cmd.getOptionValue("p"));
    }
    if (cmd.hasOption("v")) {
        factory.setVirtualHost(cmd.getOptionValue("v"));
    }
    if (cmd.hasOption("n")) {
        factory.setPort(Integer.parseInt(cmd.getOptionValue("n")));
    }

    String exchange = cmd.getOptionValue("e");
    String routingKey = "default.routing.key";
    if (cmd.hasOption("k")) {
        routingKey = cmd.getOptionValue("k");
    }

    boolean durable = cmd.hasOption("d");
    boolean autoDelete = cmd.hasOption("a");
    String type = cmd.getOptionValue("t", "topic");
    boolean single = cmd.hasOption("single");
    int interval = Integer.parseInt(cmd.getOptionValue("interval", "10"));
    int delay = Integer.parseInt(cmd.getOptionValue("delay", "100"));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date stop = sdf.parse(cmd.getOptionValue("stop", sdf.format(new Date())));

    Random r = new Random();
    Calendar timer = Calendar.getInstance();
    timer.setTime(sdf.parse(cmd.getOptionValue("start", "2010-01-01T00:00:00")));

    String msg_template = "{\"utcdt\": \"%s\", \"wp\": %d, \"gender\": \"%s\", \"age\": %d}";

    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(exchange, type, durable, autoDelete, null);

    do {
        int wp = (10 + r.nextInt(90)) * 100;
        String gender = r.nextBoolean() ? "male" : "female";
        int age = 20 + r.nextInt(70);

        String line = String.format(msg_template, sdf.format(timer.getTime()), wp, gender, age);

        channel.basicPublish(exchange, routingKey, null, line.getBytes());

        System.out.println("Sent message: " + line);

        timer.add(Calendar.SECOND, interval);

        Thread.sleep(delay);
    } while ((!single && stop.after(timer.getTime())));

    connection.close();
}

From source file:kieker.develop.rl.cli.CLICompilerMain.java

/**
 * Main method for the compiler, decoding parameter and execution
 * compilation.//  www  . j  a v a 2  s .com
 *
 * @param args
 *            command line arguments
 */
public static void main(final String[] args) {
    String runtimeRoot = "";
    String projectName = "";
    String projectSourcePath = "src";
    String projectDestinationPath = "src-gen";
    String projectDirectoryName = null;
    String authorName = "Generic Kieker";
    String version = "1.10";

    boolean mavenFolderLayout = false;
    String[] selectedLanguageTypes = {};
    int exitCode = 0;

    CLICompilerMain.declareOptions();
    try {
        // parse the command line arguments
        commandLine = new BasicParser().parse(options, args);

        if (commandLine.hasOption(CMD_ROOT)) {
            runtimeRoot = commandLine.getOptionValue(CMD_ROOT);
        }

        if (commandLine.hasOption(CMD_PROJECT)) {
            projectName = commandLine.getOptionValue(CMD_PROJECT);
        }

        if (commandLine.hasOption(CMD_PROJECT_DIRECTORY)) {
            projectDirectoryName = commandLine.getOptionValue(CMD_PROJECT_DIRECTORY);
        }

        if (commandLine.hasOption(CMD_SOURCE)) {
            projectSourcePath = commandLine.getOptionValue(CMD_SOURCE);
        }

        if (commandLine.hasOption(CMD_DESTINATION)) {
            projectDestinationPath = commandLine.getOptionValue(CMD_DESTINATION);
        }

        mavenFolderLayout = commandLine.hasOption(CMD_MAVEN_FOLDER_LAYOUT);

        if (commandLine.hasOption(CMD_LANGUAGES)) {
            selectedLanguageTypes = commandLine.getOptionValues(CMD_LANGUAGES);
        } else {
            CLICompilerMain.usage("No target languages defined.");
            System.exit(-1);
        }

        if (commandLine.hasOption(CMD_AUTHOR)) {
            authorName = commandLine.getOptionValue(CMD_AUTHOR);
        }

        if (commandLine.hasOption(CMD_VERSION)) {
            version = commandLine.getOptionValue(CMD_VERSION);
        }

        parser = new IRLParser(runtimeRoot, projectName, projectDirectoryName, projectSourcePath,
                projectDestinationPath, mavenFolderLayout, selectedLanguageTypes, version, authorName);
        parser.compileAll();
    } catch (final ParseException e) {
        CLICompilerMain.usage("Parsing failed.  Reason: " + e.getMessage());
        exitCode = 4;
    }
    System.exit(exitCode);
}

From source file:com.act.biointerpretation.sarinference.LibMcsClustering.java

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

    // Build command line parser.
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());//from   ww  w.j av  a  2 s. c  o m
    }
    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        LOGGER.error("Argument parsing failed: %s", e.getMessage());
        exitWithHelp(opts);
    }

    // Print help.
    if (cl.hasOption(OPTION_HELP)) {
        HELP_FORMATTER.printHelp(L2FilteringDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        return;
    }

    File inputCorpusFile = new File(cl.getOptionValue(OPTION_PREDICTION_CORPUS));
    File positiveInchisFile = new File(cl.getOptionValue(OPTION_POSITIVE_INCHIS));
    File sartreeFile = new File(cl.getOptionValue(OPTION_SARTREE_PATH));
    File scoredSarFile = new File(cl.getOptionValue(OPTION_SCORED_SAR_PATH));

    JavaRunnable clusterer = getClusterer(inputCorpusFile, sartreeFile);
    JavaRunnable scorer = getSarScorer(inputCorpusFile, sartreeFile, positiveInchisFile, scoredSarFile,
            SAR_SCORING_FUNCTION, THRESHOLD_TREE_SIZE);

    LOGGER.info("Running clustering.");
    clusterer.run();

    LOGGER.info("Running sar scoring.");
    scorer.run();

    LOGGER.info("Complete!.");
}

From source file:com.addthis.bark.ZkCmdLine.java

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

    Options options = new Options();
    options.addOption("h", "help", false, "something helpful.");
    options.addOption("z", "zk", true, "zk servers,port");
    options.addOption("c", "chroot", true, "chroot");
    options.addOption("n", "znode", true, "znode");
    options.addOption("d", "dir", true, "directory root");
    options.addOption("p", "put-data", true, "directory root");
    // for copying
    options.addOption("", "to-zk", true, "zk servers,port");
    options.addOption("", "to-chroot", true, "chroot");
    options.addOption("", "to-znode", true, "znode");

    CommandLineParser parser = new PosixParser();
    CommandLine cmdline = null;/*  www. j  a  v  a2s.c  om*/
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        System.exit(0);
    }

    HelpFormatter formatter = new HelpFormatter();
    if (cmdline.hasOption("help") || cmdline.getArgList().size() < 1) {
        System.out.println("commands: get jclean jcleanrecur kids grandkids");
        formatter.printHelp("ZkCmdLine", options);
        System.exit(0);
    }

    ZkCmdLine zkcl = new ZkCmdLine(cmdline);
    zkcl.runCmd((String) cmdline.getArgList().get(0));
}

From source file:com.act.biointerpretation.mechanisminspection.ReactionRenderer.java

public static void main(String[] args) throws IOException {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());//  www.  ja  v a 2 s. com
    }

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        System.err.format("Argument parsing failed: %s\n", e.getMessage());
        HELP_FORMATTER.printHelp(ReactionRenderer.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(ReactionRenderer.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        return;
    }

    Integer height = Integer.parseInt(cl.getOptionValue(OPTION_HEIGHT, "1000"));
    Integer width = Integer.parseInt(cl.getOptionValue(OPTION_WIDTH, "1000"));
    Boolean representCofactors = cl.hasOption(OPTION_COFACTOR)
            && Boolean.parseBoolean(cl.getOptionValue(OPTION_COFACTOR));

    NoSQLAPI api = new NoSQLAPI(cl.getOptionValue(OPTION_READ_DB), cl.getOptionValue(OPTION_READ_DB));

    for (String val : cl.getOptionValues(OPTION_RXN_IDS)) {
        Long reactionId = Long.parseLong(val);
        ReactionRenderer renderer = new ReactionRenderer(cl.getOptionValue(OPTION_FILE_FORMAT), width, height);
        renderer.drawReaction(api.getReadDB(), reactionId, cl.getOptionValue(OPTION_DIR_PATH),
                representCofactors);
        LOGGER.info(renderer.getSmartsForReaction(api.getReadDB(), reactionId, representCofactors));
    }
}

From source file:com.denimgroup.threadfix.cli.CommandLineParser.java

public static void main(String[] args) {

    Options options = getOptions();//from ww  w  .  j  a va  2s . c  om

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

        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar tfcli.jar", options);

        } else if (cmd.hasOption("s")) {

            String[] setArgs = cmd.getOptionValues("s");
            if (setArgs == null || setArgs.length != 2) {
                throw new ParseException("Bad arguments for set.");
            }

            if ("url".equals(setArgs[0])) {
                System.out.println("Setting URL to " + setArgs[1]);
                client.setUrl(setArgs[1]);
            } else if ("key".equals(setArgs[0])) {
                System.out.println("Setting API Key to " + setArgs[1]);
                client.setKey(setArgs[1]);
            } else {
                throw new ParseException("First argument to set must be url or key");
            }

        } else if (cmd.hasOption("ct")) {
            String[] createArgs = cmd.getOptionValues("ct");
            if (createArgs.length != 1) {
                throw new ParseException("Wrong number of arguments.");
            }
            System.out.println("Creating a Team with the name " + createArgs[0] + ".");
            System.out.println(client.createTeam(createArgs[0]));

        } else if (cmd.hasOption("cw")) {
            String[] createArgs = cmd.getOptionValues("cw");
            if (createArgs.length != 2) {
                throw new ParseException("Wrong number of arguments.");
            }
            System.out.println("Creating a Waf with the name " + createArgs[0] + ".");
            System.out.println(client.createWaf(createArgs[0], createArgs[1]));

        } else if (cmd.hasOption("ca")) {
            String[] createArgs = cmd.getOptionValues("ca");
            if (createArgs.length != 3) {
                throw new ParseException("Wrong number of arguments.");
            }
            System.out.println("Creating an Application with the name " + createArgs[1] + ".");
            System.out.println(client.createApplication(createArgs[0], createArgs[1], createArgs[2]));

        } else if (cmd.hasOption("teams")) {
            System.out.println("Getting all teams.");
            System.out.println(client.getAllTeams());

        } else if (cmd.hasOption("u")) {
            String[] uploadArgs = cmd.getOptionValues("u");
            // Upload a scan
            if (uploadArgs.length != 2) {
                throw new ParseException("Wrong number of arguments.");
            }
            System.out.println("Uploading " + uploadArgs[1] + " to Application " + uploadArgs[0] + ".");
            System.out.println(client.uploadScan(uploadArgs[0], uploadArgs[1]));

        } else if (cmd.hasOption("st")) {
            String[] searchArgs = cmd.getOptionValues("st");
            if (searchArgs.length != 2) {
                throw new ParseException("Wrong number of arguments.");
            }
            if ("id".equals(searchArgs[0])) {
                System.out.println("Searching for team with the id " + searchArgs[1] + ".");
                System.out.println(client.searchForTeamById(searchArgs[1]));
            } else if ("name".equals(searchArgs[0])) {
                System.out.println("Searching for team with the name " + searchArgs[1] + ".");
                System.out.println(client.searchForTeamByName(searchArgs[1]));
            } else {
                System.out.println("Unknown property argument. Try either id or name.");
                return;
            }

        } else if (cmd.hasOption("sw")) {
            String[] searchArgs = cmd.getOptionValues("sw");
            if (searchArgs.length != 4) {
                throw new ParseException("Wrong number of arguments.");
            }
            if ("id".equals(searchArgs[0])) {
                System.out.println("Searching for WAF with the id " + searchArgs[1] + ".");
                System.out.println(client.searchForWafById(searchArgs[1]));
            } else if ("name".equals(searchArgs[0])) {
                System.out.println("Searching for WAF with the name " + searchArgs[1] + ".");
                System.out.println(client.searchForWafByName(searchArgs[1]));
            } else {
                throw new ParseException("Unknown property argument. Try either id or name.");
            }

        } else if (cmd.hasOption("sa")) {
            String[] searchArgs = cmd.getOptionValues("sa");
            if ("id".equals(searchArgs[0])) {
                if (searchArgs.length != 2) {
                    System.out.println("Wrong number of arguments.");
                    return;
                }
                System.out.println("Searching for application with the id " + searchArgs[1] + ".");
                System.out.println(client.searchForApplicationById(searchArgs[1]));
            } else if ("name".equals(searchArgs[0])) {
                if (searchArgs.length != 3) {
                    System.out.println(
                            "Wrong number of arguments. You need to input application name and team name as well.");
                    return;
                }
                System.out.println("Searching for application with the name " + searchArgs[1] + " of team "
                        + searchArgs[2]);
                System.out.println(client.searchForApplicationByName(searchArgs[1], searchArgs[2]));
            } else {
                System.out.println("Unknown property argument. Try either id or name.");
                return;
            }

        } else if (cmd.hasOption("r")) {
            String[] ruleArgs = cmd.getOptionValues("r");
            if (ruleArgs.length != 1) {
                System.out.println("Wrong number of arguments.'");
            }
            System.out.println("Downloading rules from WAF with ID " + ruleArgs[0] + ".");
            System.out.println(client.getRules(ruleArgs[0]));

        } else {
            throw new ParseException("No arguments found.");
        }

    } catch (ParseException e) {
        if (e.getMessage() != null) {
            System.out.println(e.getMessage());
        }
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar tfcli.jar", options);
    }
}