Example usage for org.apache.commons.cli Options Options

List of usage examples for org.apache.commons.cli Options Options

Introduction

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

Prototype

Options

Source Link

Usage

From source file:fr.tpt.atlanalyser.tests.TestClass2RelationalPost2Pre.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {

    // URL resource = Thread.currentThread().getContextClassLoader()
    // .getResource("OldAGTExp");
    // System.out.println(resource.toString());
    // File f = new File(resource.getPath());
    // System.out.println(f.toString());
    // System.out.println(f.isDirectory());
    // System.exit(0);

    Options options = new Options();
    options.addOption(//  w  ww. j a va 2  s  .c o m
            OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j"));
    options.addOption(OptionBuilder.withDescription("Display help").create("h"));

    CommandLineParser parser = new BasicParser();
    int jobs = 2;
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            new HelpFormatter().printHelp(TestClass2RelationalPost2Pre.class.getSimpleName(), options);
            System.exit(0);
        }

        if (cmd.hasOption("j")) {
            jobs = Integer.parseInt(cmd.getOptionValue("j"));
        }
    } catch (Exception e) {
        System.out.println("Incorrect command line arguments");
        new HelpFormatter().printHelp(TestClass2RelationalPost2Pre.class.getSimpleName(), options);
        System.exit(1);
    }

    new TestClass2RelationalPost2Pre(models().get(0)[0], jobs).testPost2Pre();
}

From source file:com.github.braully.graph.UtilResultMerge.java

public static void main(String... args) throws Exception {
    Options options = new Options();

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(false);//www  .j  a  v  a2 s  .co  m
    options.addOption(input);

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

    Option verb = new Option("v", "verbose", false, "verbose");
    output.setRequired(false);
    options.addOption(verb);

    Option exluces = new Option("x", "exclude", true, "exclude operations");
    exluces.setRequired(false);
    options.addOption(exluces);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("UtilResult", options);

        System.exit(1);
        return;
    }

    String[] excludes = cmd.getOptionValues("exclude");
    String[] inputs = cmd.getOptionValues("input");
    if (inputs == null) {
        inputs = new String[] {
                "/home/strike/Dropbox/workspace/graph-caratheodory-np3/grafos-processamento/Almost_hypohamiltonian"
                //                "/media/dados/documentos/grafos-processamento/Almost_hypohamiltonian",
                //                "/home/strike/Documentos/grafos-processamento/Cubic",
                //                "/home/strike/Documentos/grafos-processamento/Critical_H-free",
                //                "/home/strike/Documentos/grafos-processamento/Highly_irregular",
                //                "/home/strike/Documentos/grafos-processamento/Hypohamiltonian_graphs",
                //                "/home/strike/Documentos/grafos-processamento/Maximal_triangle-free",
                //                "/home/strike/Documentos/grafos-processamento/Minimal_Ramsey",
                //                "/home/strike/Documentos/grafos-processamento/Strongly_regular",
                //                "/home/strike/Documentos/grafos-processamento/Vertex-transitive",
                //                "/home/strike/Documentos/grafos-processamento/Trees"
        };
        excludes = new String[] { "carathe" };
        verbose = true;
    }

    if (cmd.hasOption(verb.getOpt())) {
        verbose = true;
    }

    if (inputs != null) {
        processInputs(inputs, excludes);
    }
}

From source file:com.shieldsbetter.sbomg.Cli.java

public static void main(String[] args) {
    int result;/*from   w w w  .j  a v  a  2 s.c  om*/

    try {
        Options options = new Options();
        options.addOption("f", false, "Force overwrite of files that already exist.");
        options.addOption("q", false, "Quiet all non-error output.");

        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(options, args);

        try {
            Plan p = makePlan(cmd);

            for (File input : p.files()) {
                if (!cmd.hasOption('q')) {
                    System.out.println("Processing " + input.getPath() + "...");
                }

                String modelName = nameWithoutExtension(input);
                File targetPath = p.getDestinationPath(input);
                try (Scanner inputScan = fileToScanner("input", input);
                        Writer outputWriter = outputPathToWriter(targetPath, modelName, cmd);) {
                    Object modelDesc = parseSbomgV1(inputScan);

                    try {
                        ViewModelGenerator.generate(p.getPackage(input), modelName, modelDesc, outputWriter);
                    } catch (IOException ioe) {
                        throw new FileException(buildOutputFile(targetPath, modelName), "writing to target",
                                ioe.getMessage());
                    }
                } catch (IOException ioe) {
                    throw new FileException(buildOutputFile(targetPath, modelName), "opening target",
                            ioe.getMessage());
                }
            }

            result = 0;
        } catch (OperationException oe) {
            System.err.println();
            System.err.println(oe.getMessage());
            result = 1;
        }
    } catch (FileException fe) {
        System.err.println();
        System.err.println("Error " + fe.getTask() + " file " + fe.getFile().getPath() + ":");
        System.err.println("    " + fe.getMessage());

        result = 1;
    } catch (ParseException pe) {
        throw new RuntimeException(pe);
    }

    System.exit(result);
}

From source file:com.rapleaf.hank.cli.AddRing.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("r", "ring-group", true, "the name of the ring group");
    options.addOption("n", "ring-number", true, "the number of the new ring you are creating");
    options.addOption("h", "hosts", true, "a comma-separated list of host:port pairs");
    options.addOption("c", "config", true,
            "path of a valid config file with coordinator connection information");
    try {//from   w  w w.  j  a v  a  2 s  . c  o m
        CommandLine line = new GnuParser().parse(options, args);
        CommandLineChecker.check(line, options, new String[] { "config", "ring-group", "ring-number" },
                AddRing.class);
        ClientConfigurator configurator = new YamlClientConfigurator(line.getOptionValue("config"));
        addRing(configurator, line.getOptionValue("ring-group"),
                Integer.parseInt(line.getOptionValue("ring-number")), line.getOptionValue("hosts"));
    } catch (ParseException e) {
        new HelpFormatter().printHelp("add_domain", options);
        throw e;
    }
}

From source file:com.github.zk1931.zabkv.Main.java

public static void main(String[] args) throws Exception {
    // Options for command arguments.
    Options options = new Options();

    Option port = OptionBuilder.withArgName("port").hasArg(true).isRequired(true).withDescription("port number")
            .create("port");

    Option ip = OptionBuilder.withArgName("ip").hasArg(true).isRequired(true)
            .withDescription("current ip address").create("ip");

    Option join = OptionBuilder.withArgName("join").hasArg(true).withDescription("the addr of server to join.")
            .create("join");

    Option help = OptionBuilder.withArgName("h").hasArg(false).withLongOpt("help")
            .withDescription("print out usages.").create("h");

    options.addOption(port).addOption(ip).addOption(join).addOption(help);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd;/* w w  w.j a  va 2  s  .c  o m*/

    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("zabkv", options);
            return;
        }
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("zabkv", options);
        return;
    }

    int zabPort = Integer.parseInt(cmd.getOptionValue("port"));
    String myIp = cmd.getOptionValue("ip");

    if (zabPort < 5000 && zabPort >= 5010) {
        System.err.println("port parameter can have value only between 5000 & 5010");
        System.exit(1);
    }

    int serverPort = zabPort % 5000 + 8000;

    Database db = new Database(myIp, zabPort, cmd.getOptionValue("join"));

    Server server = new Server(serverPort);
    ServletHandler handler = new ServletHandler();
    server.setHandler(handler);
    ServletHolder holder = new ServletHolder(new RequestHandler(db));
    handler.addServletWithMapping(holder, "/*");
    server.start();
    server.join();
    System.out.println("hi");
}

From source file:com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {/*from  w w w.ja va 2 s.c  o  m*/
        Options options = new Options();
        options.addOption("h", "help", false, "show usage");
        options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg()
                .argName("PROJECT-ID").required(true).build());
        CommandLine cl = (new DefaultParser()).parse(options, args);
        if (cl.hasOption("help")) {
            HelpFormatter formater = new HelpFormatter();
            formater.printHelp("ReportErrorsServiceSmokeTest", options);
        }
        executeNoCatch(cl.getOptionValue("project_id"));
        System.out.println("OK");
    } catch (Exception e) {
        System.err.println("Failed with exception:");
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequencyJson.java

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

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));

    CommandLine cmdline = null;//  w ww  .j a  v a2 s  .co m
    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)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(AnalyzeBigramRelativeFrequencyJson.class.getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    System.out.println("input path: " + inputPath);

    List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> pairs = SequenceFileUtils
            .readDirectory(new Path(inputPath));

    List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> list1 = Lists.newArrayList();
    List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> list2 = Lists.newArrayList();

    for (PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p : pairs) {
        BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement();

        if (bigram.getJsonObject().get("Left").getAsString().equals("light")) {
            list1.add(p);
        }

        if (bigram.getJsonObject().get("Left").getAsString().equals("contain")) {
            list2.add(p);
        }
    }

    Collections.sort(list1,
            new Comparator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>>() {
                public int compare(PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e1,
                        PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e2) {
                    if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                        return e1.getLeftElement().compareTo(e2.getLeftElement());
                    }

                    return e2.getRightElement().compareTo(e1.getRightElement());
                }
            });

    Iterator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> iter1 = Iterators
            .limit(list1.iterator(), 10);
    while (iter1.hasNext()) {
        PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p = iter1.next();
        BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }

    Collections.sort(list2,
            new Comparator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>>() {
                public int compare(PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e1,
                        PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e2) {
                    if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                        return e1.getLeftElement().compareTo(e2.getLeftElement());
                    }

                    return e2.getRightElement().compareTo(e1.getRightElement());
                }
            });

    Iterator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> iter2 = Iterators
            .limit(list2.iterator(), 10);
    while (iter2.hasNext()) {
        PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p = iter2.next();
        BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }
}

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

/**
 * Entry point for Scale command./*  w ww  .  java2 s.c o m*/
 * @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);
    }
}

From source file:com.kylinolap.query.QueryCli.java

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

    Options options = new Options();
    options.addOption(OPTION_METADATA);//from   w  w  w.  j  a va  2  s .  c  o  m
    options.addOption(OPTION_SQL);

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = parser.parse(options, args);
    KylinConfig config = KylinConfig
            .createInstanceFromUri(commandLine.getOptionValue(OPTION_METADATA.getOpt()));
    String sql = commandLine.getOptionValue(OPTION_SQL.getOpt());

    Class.forName("net.hydromatic.optiq.jdbc.Driver");
    File olapTmp = OLAPSchemaFactory.createTempOLAPJson(null, config);

    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = DriverManager.getConnection("jdbc:optiq:model=" + olapTmp.getAbsolutePath());

        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        int n = 0;
        ResultSetMetaData meta = rs.getMetaData();
        while (rs.next()) {
            n++;
            for (int i = 1; i <= meta.getColumnCount(); i++) {
                System.out.println(n + " - " + meta.getColumnLabel(i) + ":\t" + rs.getObject(i));
            }
        }
    } finally {
        if (rs != null) {
            rs.close();
        }
        if (stmt != null) {
            stmt.close();
        }
        if (conn != null) {
            conn.close();
        }
    }

}

From source file:com.adobe.aem.demomachine.Checksums.java

public static void main(String[] args) {

    String rootFolder = null;/* w  ww. j a v  a2  s . co  m*/

    // Command line options for this tool
    Options options = new Options();
    options.addOption("f", true, "Demo Machine root folder");
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("f")) {
            rootFolder = cmd.getOptionValue("f");
        }

    } catch (Exception e) {
        System.exit(-1);
    }

    Properties md5properties = new Properties();
    List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths);
    for (String[] path : listPaths) {
        if (path.length == 5) {
            logger.debug(path[1]);
            File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : ""));
            if (pathFolder.exists()) {
                String md5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false);
                logger.debug("MD5 is: " + md5);
                md5properties.setProperty("demo.path." + path[0], path[1]);
                md5properties.setProperty("demo.md5." + path[0], md5);
            } else {
                logger.error("Folder cannot be found");
            }
        }
    }

    File md5 = new File(rootFolder + File.separator + "conf" + File.separator + "checksums.properties");
    try {

        @SuppressWarnings("serial")
        Properties tmpProperties = new Properties() {
            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(new TreeSet<Object>(super.keySet()));
            }
        };
        tmpProperties.putAll(md5properties);
        tmpProperties.store(new FileOutputStream(md5), null);
    } catch (Exception e) {
        logger.error(e.getMessage());
    }

    System.out.println("MD5 checkums generated");

}