Example usage for org.apache.commons.cli CommandLineParser parse

List of usage examples for org.apache.commons.cli CommandLineParser parse

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLineParser parse.

Prototype

CommandLine parse(Options options, String[] arguments) throws ParseException;

Source Link

Document

Parse the arguments according to the specified options.

Usage

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

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());// ww  w . j ava  2 s  .co m
    }

    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(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

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

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

    Map<Integer, List<Ero>> results = validator
            .validateOneReaction(Long.parseLong(cl.getOptionValue(OPTION_RXN_ID)));

    if (results == null) {
        System.out.format("ERROR: validation results are null.\n");
    } else if (results.size() == 0) {
        System.out.format("No matching EROs were found for the specified reaction.\n");
    } else {
        for (Map.Entry<Integer, List<Ero>> entry : results.entrySet()) {
            List<String> eroIds = entry.getValue().stream().map(x -> x.getId().toString())
                    .collect(Collectors.toList());
            System.out.format("%d: %s\n", entry.getKey(), StringUtils.join(eroIds, ", "));
        }
    }
}

From source file:com.ctriposs.rest4j.tools.idlgen.Rest4JResourceModelExporterCmdLineApp.java

/**
 * @param args rest4jexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir]
 *///from  w  w w .  j  ava 2s. c o m
public static void main(String[] args) {
    //    args = new String[] {"-name", "groups",
    //                         "-resourcepackages", "com.ctriposs.groups.server.rest1.impl com.ctriposs.groups.server.rest2.impl ",
    //                         "-resourceclasses", "com.ctriposs.groups.server.restX.impl.FooResource",
    //                         "-sourcepath", "src/main/java",
    //                         "-outdir", "src/codegen/idl",
    //                         "-split"};

    CommandLine cl = null;
    try {
        final CommandLineParser parser = new GnuParser();
        cl = parser.parse(OPTIONS, args);
    } catch (ParseException e) {
        System.err.println("Invalid arguments: " + e.getMessage());
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(
                "rest4jexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]"
                        + "[-name api_name] [-outdir outdir]",
                OPTIONS);
        System.exit(0);
    }

    try {
        new Rest4JResourceModelExporter().export(cl.getOptionValue("name"), null,
                cl.getOptionValues("sourcepath"), cl.getOptionValues("resourcepackages"),
                cl.getOptionValues("resourceclasses"), cl.getOptionValue("outdir", "."));
    } catch (Throwable e) {
        log.error("Error writing IDL files", e);
        System.exit(1);
    }
}

From source file:it.serasoft.pdi.PDITools.java

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

    Options opts = new Options();

    opts.addOption("report", false, "Generate a report documenting the procedures under analysis");

    opts.addOption("follow", true, "Values: directory, links, none");
    opts.addOption("outDir", true, "Path to output directory where we will write eventual output files");
    opts.addOption("srcDir", true, "Path to base directory containing the PDI processes source");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmdLine = parser.parse(opts, args);

    String outDir = cmdLine.hasOption("outDir") ? cmdLine.getOptionValue("outDir") : null;
    String srcDir = cmdLine.hasOption("srcDir") ? cmdLine.getOptionValue("srcDir") : null;
    String follow = cmdLine.hasOption("follow") ? cmdLine.getOptionValue("follow") : FOLLOW_DIR;
    // Follow links between procedures only if required and recurseSubdir = false (DEFAULT)
    boolean recurseDir = follow.equals(FOLLOW_DIR);
    boolean followLinks = follow.equals(FOLLOW_PROCLINKS);

    startReadingDir(srcDir, recurseDir, followLinks);
}

From source file:name.ikysil.beanpathdsl.codegen.CLI.java

/**
 * @param args the command line arguments
 *//*from  w w w.  j  a  v a2  s  .c o m*/
public static void main(String[] args) {
    final Options options = buildOptions();
    try {
        CommandLineParser parser = new DefaultParser();
        CommandLine cmdLine = parser.parse(options, args);
        if (cmdLine.hasOption("h")) {
            usage(options);
            System.exit(1);
        }
        Configuration configuration = new Configuration();
        if (cmdLine.hasOption("s")) {
            configuration.setOutputDirectory(cmdLine.getOptionValue("s"));
        }
        if (cmdLine.hasOption("c")) {
            configuration.setOutputCharset(Charset.forName(cmdLine.getOptionValue("c")));
        }
        if (cmdLine.hasOption("cnp")) {
            configuration.setClassNamePrefix(cmdLine.getOptionValue("cnp"));
        }
        if (cmdLine.hasOption("cns")) {
            configuration.setClassNameSuffix(cmdLine.getOptionValue("cns"));
        }
        if (cmdLine.hasOption("pnp")) {
            configuration.setPackageNamePrefix(cmdLine.getOptionValue("pnp"));
        }
        if (cmdLine.hasOption("pns")) {
            configuration.setPackageNameSuffix(cmdLine.getOptionValue("pns"));
        }
        new CodeGen(configuration).process();
    } catch (ParseException ex) {
        System.err.println(String.format("Can not parse arguments: %s", ex.getMessage()));
        usage(options);
    }
}

From source file:com.act.biointerpretation.cofactorremoval.ReactionCofactorRemover.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());/* ww  w . j  ava  2 s .  c  om*/
    }

    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(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

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

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

    CofactorRemover cofactorRemover = new CofactorRemover(api);
    cofactorRemover.init();

    Pair<Reaction, Reaction> results = cofactorRemover
            .removeCofactorsFromOneReaction(Long.parseLong(cl.getOptionValue(OPTION_RXN_ID)));

    System.out.format("Reaction before processing:\n");
    printReport(results.getLeft());
    System.out.println();
    System.out.format("Reaction after processing:\n");
    printReport(results.getRight());
    System.out.println();
}

From source file:graphgen.GraphGen.java

/**
 * @param args the command line arguments
 *///from w  w  w .j  a  v  a2  s . c  o m
public static void main(String[] args) {
    Options options = new Options();
    HelpFormatter formatter = new HelpFormatter();

    options.addOption(OPTION_EDGES, true, OPTION_EDGES_MSG);
    options.addOption(OPTION_NODES, true, OPTION_NODES_MSG);
    options.addOption(OPTION_OUTPUT, true, OPTION_OUTPUT_MSG);

    CommandLineParser parser = new BasicParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        int edgeCount = Integer.valueOf(cmd.getOptionValue(OPTION_EDGES));
        int nodeCount = Integer.valueOf(cmd.getOptionValue(OPTION_NODES));
        String outputFile = cmd.getOptionValue(OPTION_OUTPUT);

        if ((nodeCount < edgeCount) || (outputFile != null)) {
            String graph = generateGraph(nodeCount, edgeCount);
            saveGraph(graph, outputFile);
        } else {
            formatter.printHelp(HELP_NAME, options);
        }

    } catch (NumberFormatException | ParseException e) {
        formatter.printHelp(HELP_NAME, options);
    } catch (IllegalArgumentException | FileNotFoundException e) {
        System.err.println(e.getMessage());
    }
}

From source file:dk.statsbiblioteket.jpar2.filecompare.FileCompare.java

/**
 * Main method. //  w  ww  . j  a  v a2s.  c  om
 * @param args
 */
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("s", "slices", true, "The number of slices to use in the comparison");

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        args = cmd.getArgs();
        if (!cmd.hasOption("s") || args.length != 2) {
            System.exit(2);
        }
        int slices = Integer.parseInt(cmd.getOptionValue("s").trim());

        File f1 = new File(args[0]);
        File f2 = new File(args[1]);
        if (f1.length() == f2.length()) {
            int sliceSize = (int) (f1.length() / slices);//rounding here...

            DataFile df1 = new DataFile(f1, sliceSize);
            DataFile df2 = new DataFile(f2, sliceSize);

            List<Integer> defectIndexes = df1.compareWithIndex(df2);

            for (int index : defectIndexes) {
                System.out.println("index " + index + ", from " + index * sliceSize + " to "
                        + (index + 1) * sliceSize + " is defect");
            }
            if (defectIndexes.size() == 0) {
                System.out.println("Files are identical");
            }

        } else {
            System.out.println("Files differ in length, cannot help you");
        }
    } catch (ParseException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

}

From source file:com.act.lcms.db.io.report.IonAnalysisInterchangeModelOperations.java

public static void main(String[] args) throws IOException {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());//from  w  w w .  ja v a  2  s .  co 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());
        HELP_FORMATTER.printHelp(IonAnalysisInterchangeModelOperations.class.getCanonicalName(), HELP_MESSAGE,
                opts, null, true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(IonAnalysisInterchangeModelOperations.class.getCanonicalName(), HELP_MESSAGE,
                opts, null, true);
        System.exit(1);
    }

    if (cl.hasOption(OPTION_LOG_DISTRIBUTION)) {
        IonAnalysisInterchangeModel model = new IonAnalysisInterchangeModel();
        model.loadResultsFromFile(new File(cl.getOptionValue(OPTION_INPUT_FILE)));
        Map<Pair<Double, Double>, Integer> rangeToCount = model
                .computeLogFrequencyDistributionOfMoleculeCountToMetric(
                        IonAnalysisInterchangeModel.METRIC.valueOf(cl.getOptionValue(OPTION_LOG_DISTRIBUTION)));

        try (BufferedWriter predictionWriter = new BufferedWriter(
                new FileWriter(new File(OPTION_OUTPUT_FILE)))) {
            for (Map.Entry<Pair<Double, Double>, Integer> entry : rangeToCount.entrySet()) {
                String value = String.format("%f,%d", entry.getKey().getLeft(), entry.getValue());
                predictionWriter.write(value);
                predictionWriter.newLine();
            }
        }
    }
}

From source file:com.dattack.dbping.cli.PingCli.java

/**
 * The <code>main</code> method.
 *
 * @param args//w  w w . j  av  a2s.c  o  m
 *            the program arguments
 */
public static void main(final String[] args) {

    final Options options = createOptions();

    try {
        final CommandLineParser parser = new DefaultParser();
        final CommandLine cmd = parser.parse(options, args);
        final String[] filenames = cmd.getOptionValues(FILE_OPTION);
        final String[] taskNames = cmd.getOptionValues(TASK_NAME_OPTION);

        HashSet<String> hs = null;
        if (taskNames != null) {
            hs = new HashSet<>(Arrays.asList(taskNames));
        }

        final PingEngine ping = new PingEngine();
        ping.execute(filenames, hs);

    } catch (@SuppressWarnings("unused") final ParseException e) {
        showUsage(options);
    } catch (final ConfigurationException | DattackParserException e) {
        System.err.println(e.getMessage());
    }
}

From source file:de.drippinger.serviceExtractor.CLIEntry.java

public static void main(String... args) {

    Banner.printBanner();//  w  ww .  j  ava  2  s  . c om

    try {

        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(createOptions(), args);
        RunParameter parameter = null;

        if (cmd.hasOption("h")) {
            printHelp();
        } else if (cmd.hasOption("c")) {
            parameter = extractParameterFromConfigFile(cmd);
        } else {
            parameter = extractParameterFromCommandline(cmd);
        }

        if (parameter != null && parameter.hasSufficientData()) {
            parameter.printParameter();
            // TODO Do main stuff
        } else {
            log.warn("Not sufficient parameters provided. exiting");
        }

    } catch (ParseException | ExtractorException e) {
        log.error(e.toString());
    }
}