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:io.github.the28awg.okato.App.java

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

    options.addOption(Option.builder().longOpt("token").hasArg().required().argName("token")
            .desc(" ? ?  ??").build());
    options.addOption(Option.builder("t").longOpt("type").hasArg().required().argName("type")
            .desc("  [city, street, building]").build());
    options.addOption(Option.builder("q").longOpt("query").hasArg().argName("query")
            .desc(" ? ?  ").build());
    options.addOption(Option.builder("c").longOpt("city_id").hasArg().argName("city_id")
            .desc("  (? )").build());
    options.addOption(Option.builder("s").longOpt("street_id").hasArg().argName("street_id")
            .desc(" ").build());

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;/*from   w  w w.ja va2s  .  com*/

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

    AddressFactory.token(cmd.getOptionValue("token"));

    String arg_type = cmd.getOptionValue("type");
    String arg_city_id = cmd.getOptionValue("city_id", "");
    String arg_street_id = cmd.getOptionValue("street_id", "");
    String arg_query = cmd.getOptionValue("query", "");
    if (arg_type.equalsIgnoreCase("city")) {
        try {
            log(SimpleOkato.toSimpleResponse(
                    AddressFactory.service().city(AddressFactory.token(), arg_query).execute().body()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else if (arg_type.equalsIgnoreCase("street")) {
        try {
            log(SimpleOkato.toSimpleResponse(AddressFactory.service()
                    .street(AddressFactory.token(), arg_city_id, arg_query).execute().body()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else if (arg_type.equalsIgnoreCase("building")) {
        try {
            log(SimpleOkato.toSimpleResponse(AddressFactory.service()
                    .building(AddressFactory.token(), arg_city_id, arg_street_id, arg_query).execute().body()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

From source file:com.chriscx.similarity.SimilarityApp.java

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

    Options options = new Options();

    options.addOption("i", true, "input folder");
    options.addOption("o", true, "output folder");

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

    if (args.length > 1) {

    }/*  ww  w.  ja v a  2  s  . com*/
}

From source file:io.minimum.minecraft.rbclean.RedisBungeeClean.java

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

    Option hostOption = new Option("h", "host", true, "Sets the Redis host to use.");
    hostOption.setRequired(true);//from w  w  w . j av a  2s . co  m
    options.addOption(hostOption);

    Option portOption = new Option("p", "port", true, "Sets the Redis port to use.");
    options.addOption(portOption);

    Option passwordOption = new Option("w", "password", true, "Sets the Redis password to use.");
    options.addOption(passwordOption);

    Option dryRunOption = new Option("d", "dry-run", false, "Performs a dry run (no data is modified).");
    options.addOption(dryRunOption);

    CommandLine commandLine;

    try {
        commandLine = new DefaultParser().parse(options, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("RedisBungeeClean", options);
        return;
    }

    int port = commandLine.hasOption('p') ? Integer.parseInt(commandLine.getOptionValue('p')) : 6379;

    try (Jedis jedis = new Jedis(commandLine.getOptionValue('h'), port, 0)) {
        if (commandLine.hasOption('w')) {
            jedis.auth(commandLine.getOptionValue('w'));
        }

        System.out.println("Fetching UUID cache...");
        Map<String, String> uuidCache = jedis.hgetAll("uuid-cache");
        Gson gson = new Gson();

        // Just in case we need it, compress everything in JSON format.
        if (!commandLine.hasOption('d')) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
            File file = new File("uuid-cache-previous-" + dateFormat.format(new Date()) + ".json.gz");
            try {
                file.createNewFile();
            } catch (IOException e) {
                System.out.println("Can't write backup of the UUID cache, will NOT proceed.");
                e.printStackTrace();
                return;
            }

            System.out.println("Creating backup (as " + file.getName() + ")...");

            try (OutputStreamWriter bw = new OutputStreamWriter(
                    new GZIPOutputStream(new FileOutputStream(file)))) {
                gson.toJson(uuidCache, bw);
            } catch (IOException e) {
                System.out.println("Can't write backup of the UUID cache, will NOT proceed.");
                e.printStackTrace();
                return;
            }
        }

        System.out.println("Cleaning out the bird cage (this may take a while...)");
        int originalSize = uuidCache.size();
        for (Iterator<Map.Entry<String, String>> it = uuidCache.entrySet().iterator(); it.hasNext();) {
            CachedUUIDEntry entry = gson.fromJson(it.next().getValue(), CachedUUIDEntry.class);

            if (entry.expired()) {
                it.remove();
            }
        }
        int newSize = uuidCache.size();

        if (commandLine.hasOption('d')) {
            System.out.println(
                    (originalSize - newSize) + " records would be expunged if a dry run was not conducted.");
        } else {
            System.out.println("Expunging " + (originalSize - newSize) + " records...");
            Transaction transaction = jedis.multi();
            transaction.del("uuid-cache");
            transaction.hmset("uuid-cache", uuidCache);
            transaction.exec();
            System.out.println("Expunging complete.");
        }
    }
}

From source file:com.dal.a.main.EncyclopediaMain.java

public static void main(String[] args) {
    Encyclopedia app = new Encyclopedia();
    Options opts = new Options();

    try {//  w  w  w.jav a  2s . c  o  m
        app.config(new PosixParser().parse(opts, args));
    } catch (ParseException ex) {
        LOG.error("parse exception during main", ex);
    }

    app.setVisible(true);
}

From source file:mosaicsimulation.MosaicLockstepServer.java

public static void main(String[] args) {
    Options opts = new Options();
    opts.addOption("s", "serverPort", true, "Listening TCP port used to initiate handshakes");
    opts.addOption("n", "nClients", true, "Number of clients that will participate in the session");
    opts.addOption("t", "tickrate", true, "Number of transmission session to execute per second");
    opts.addOption("m", "maxUDPPayloadLength", true, "Max number of bytes per UDP packet");
    opts.addOption("c", "connectionTimeout", true, "Timeout for UDP connections");

    DefaultParser parser = new DefaultParser();
    CommandLine commandLine = null;//from w  ww . j a  va 2 s . c o m
    try {
        commandLine = parser.parse(opts, args);
    } catch (ParseException ex) {
        ex.printStackTrace();
        System.exit(1);
    }

    int serverPort = Integer.parseInt(commandLine.getOptionValue("serverPort"));
    int nClients = Integer.parseInt(commandLine.getOptionValue("nClients"));
    int tickrate = Integer.parseInt(commandLine.getOptionValue("tickrate"));
    int maxUDPPayloadLength = Integer.parseInt(commandLine.getOptionValue("maxUDPPayloadLength"));
    int connectionTimeout = Integer.parseInt(commandLine.getOptionValue("connectionTimeout"));

    Thread serverThread = LockstepServer.builder().clientsNumber(nClients).tcpPort(serverPort)
            .tickrate(tickrate).maxUDPPayloadLength(maxUDPPayloadLength).connectionTimeout(connectionTimeout)
            .build();

    serverThread.setName("Main-server-thread");
    serverThread.start();

    try {
        serverThread.join();
    } catch (InterruptedException ex) {
        LOG.error("Server interrupted while joining");
    }
}

From source file:com.tomdoel.mpg2dcm.Mpg2Dcm.java

public static void main(String[] args) {
    try {//from   w ww .j  a  v  a 2 s.  c o  m
        final Options helpOptions = new Options();
        helpOptions.addOption("h", false, "Print help for this application");

        final DefaultParser parser = new DefaultParser();
        final CommandLine commandLine = parser.parse(helpOptions, args);

        if (commandLine.hasOption('h')) {
            final String helpHeader = "Converts an mpeg2 video file to Dicom\n\n";
            String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm";

            final HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("Mpg2Dcm mpegfile dicomfile", helpHeader, helpOptions, helpFooter, true);

        } else {
            final List<String> remainingArgs = commandLine.getArgList();
            if (remainingArgs.size() < 2) {
                throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified.");
            }

            final String mpegFileName = remainingArgs.get(0);
            final String dicomFileName = remainingArgs.get(1);
            final File mpegFile = new File(mpegFileName);
            final File dicomOutputFile = new File(dicomFileName);
            MpegFileConverter.convert(mpegFile, dicomOutputFile);
        }
    } catch (org.apache.commons.cli.ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:StompMessageConsumer.java

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

    Options options = new Options();
    options.addOption("h", true, "Host to connect to");
    options.addOption("p", true, "Port to connect to");
    options.addOption("u", true, "User name");
    options.addOption("P", true, "Password");

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

    String host = "192.168.1.7";
    String port = "61613";
    String user = "guest";
    String pass = "P@ssword1";

    if (cmd.hasOption("h")) {
        host = cmd.getOptionValue("h");
    }/*from   w ww  .  j a  v  a  2s . c  o m*/
    if (cmd.hasOption("p")) {
        port = cmd.getOptionValue("p");
    }
    if (cmd.hasOption("u")) {
        user = cmd.getOptionValue("u");
    }
    if (cmd.hasOption("P")) {
        pass = cmd.getOptionValue("P");
    }

    try {
        StompConnection connection = new StompConnection();

        connection.open(host, Integer.parseInt(port));
        connection.connect(user, pass);
        //      connection.open("orange.cloudtroopers.ro", 61613);
        //      connection.connect("system", "manager");

        connection.subscribe("jms.queue.memberRegistration", Subscribe.AckModeValues.CLIENT);
        connection.subscribe(StompMessagePublisher.MEMBER_REGISTRATION_JMS_DESTINATION,
                Subscribe.AckModeValues.CLIENT);

        connection.begin("tx2");
        StompFrame message = connection.receive();
        System.out.println(message.getBody());
        connection.ack(message, "tx2");
        connection.commit("tx2");

        connection.disconnect();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.sourcethought.simpledaemon.EchoTask.java

public static void main(String[] args) throws Exception {
    // setup command line options
    Options options = new Options();
    options.addOption("h", "help", false, "print this help screen");

    // read command line options
    CommandLineParser parser = new PosixParser();
    try {/*from   w w w .j a  v a2 s . co  m*/
        CommandLine cmdline = parser.parse(options, args);

        if (cmdline.hasOption("help") || cmdline.hasOption("h")) {
            System.out.println("SimpleDaemon Version " + Main.version);

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(
                    "java -cp lib/*:target/SimpleDaemon-1.0-SNAPSHOT.jar com.sourcethought.simpledaemon.Main",
                    options);
            return;
        }

        final SimpleDaemon daemon = new SimpleDaemon();
        daemon.start();

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                if (daemon.isRunning()) {
                    try {
                        System.out.println("Shutting down daemon...");
                        daemon.stop();
                    } catch (Exception ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }));

    } catch (ParseException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.basingwerk.utilisation.Utilisation.java

public static void main(final String[] args) {
    String dataFile = null;// w w w .j  a  v  a 2s . c o  m

    Options options = new Options();

    Option helpOption = new Option("h", "help", false, "print this help");
    Option serverURLOption = new Option("l", "logfile", true, "log file");

    options.addOption(helpOption);
    options.addOption(serverURLOption);

    CommandLineParser argsParser = new PosixParser();

    try {
        CommandLine commandLine = argsParser.parse(options, args);

        if (commandLine.hasOption(helpOption.getOpt())) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

        dataFile = commandLine.getOptionValue(serverURLOption.getOpt());
        String[] otherArgs = commandLine.getArgs();

        if (dataFile == null || otherArgs.length > 1) {
            System.out.println("Please specify a logfile");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
    }

    final UsagePlotter demo = new UsagePlotter("Usage", new File(dataFile));
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
}

From source file:io.github.azige.mages.Cli.java

public static void main(String[] args) {

    Options options = new Options().addOption("h", "help", false, "print this message")
            .addOption(Option.builder("r").hasArg().argName("bundle").desc("set the ResourceBundle").build())
            .addOption(Option.builder("l").hasArg().argName("locale").desc("set the locale").build())
            .addOption(Option.builder("t").hasArg().argName("template").desc("set the template").build())
            .addOption(Option.builder("p").hasArg().argName("plugin dir")
                    .desc("set the directory to load plugins").build())
            .addOption(Option.builder("f").desc("force override existed file").build());
    try {/*w  ww.  ja va  2 s.  c o  m*/
        CommandLineParser parser = new DefaultParser();
        CommandLine cl = parser.parse(options, args);

        if (cl.hasOption('h')) {
            printHelp(System.out, options);
            return;
        }

        MagesSiteGenerator msg = new MagesSiteGenerator(new File("."), new File("."));

        String[] fileArgs = cl.getArgs();
        if (fileArgs.length < 1) {
            msg.addTask(".");
        } else {
            for (String path : fileArgs) {
                msg.addTask(path);
            }
        }

        if (cl.hasOption("t")) {
            msg.setTemplate(new File(cl.getOptionValue("t")));
        }

        if (cl.hasOption("r")) {
            msg.setResource(new File(cl.getOptionValue("r")));
        } else {
            File resource = new File("Resource.properties");
            if (resource.exists()) {
                msg.setResource(resource);
            }
        }

        if (cl.hasOption("p")) {
            msg.setPluginDir(new File(cl.getOptionValue("p")));
        }

        if (cl.hasOption("f")) {
            msg.setForce(true);
        }

        msg.start();
    } catch (ParseException ex) {
        System.err.println(ex.getMessage());
        printHelp(System.err, options);
    }
}