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

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

Introduction

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

Prototype

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

Source Link

Document

Parses the specified arguments based on the specifed Options .

Usage

From source file:com.cloudera.impala.testutil.SentryServiceWrapper.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    // Parse command line options to get config file path.
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("config_file")
            .withDescription("Absolute path to a sentry-site.xml config file").hasArg()
            .withArgName("CONFIG_FILE").isRequired().create('c'));
    BasicParser optionParser = new BasicParser();
    CommandLine cmdArgs = optionParser.parse(options, args);

    SentryServiceWrapper server = new SentryServiceWrapper(
            new SentryConfig(cmdArgs.getOptionValue("config_file")));
    server.start();/*from w  w  w  .  j ava 2  s. co  m*/
}

From source file:com.redhat.poc.jdg.bankofchina.util.GenerateUserIdCsv.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/*  w ww. j ava 2  s. co  m*/
    Options options = new Options();
    options.addOption("s", true, "The start csv file number option");
    options.addOption("e", true, "The end csv file number option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("s")) {
            String start = commandLine.getOptionValue("s");
            if (start != null && start.length() > 0) {
                csvFileStart = Integer.parseInt(start);
            }
        }
        if (commandLine.hasOption("e")) {
            String end = commandLine.getOptionValue("e");
            if (end != null && end.length() > 0) {
                csvFileEnd = Integer.parseInt(end);
            }
        }
    }

    for (int i = csvFileStart; i <= csvFileEnd; i++) {
        ReadCsvFile(i);
    }

    System.out.println();
    System.out.println("%%%%%%%%%  " + csvFileStart + "-" + csvFileEnd
            + " ? userid.csv ,? %%%%%%%%%");
    System.out.println("%%%%%%%%% userid.csv  " + userIdList.size() + " ? %%%%%%%%%");
    CSVWriter writer = new CSVWriter(new FileWriter(CSV_FILE_PATH + "userid.csv"));
    writer.writeAll(userIdList);
    writer.flush();
    writer.close();
}

From source file:com.cloudera.impala.testutil.SentryServicePinger.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    // Parse command line options to get config file path.
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("config_file")
            .withDescription("Absolute path to a sentry-site.xml config file (string)").hasArg()
            .withArgName("CONFIG_FILE").isRequired().create('c'));
    options.addOption(OptionBuilder.withLongOpt("num_pings")
            .withDescription("Max number of pings to try before failing (int)").hasArg().isRequired()
            .withArgName("NUM_PINGS").create('n'));
    options.addOption(//from   w  ww .j a va2s.  co m
            OptionBuilder.withLongOpt("sleep_secs").withDescription("Time (s) to sleep between pings (int)")
                    .hasArg().withArgName("SLEEP_SECS").create('s'));
    BasicParser optionParser = new BasicParser();
    CommandLine cmdArgs = optionParser.parse(options, args);

    SentryConfig sentryConfig = new SentryConfig(cmdArgs.getOptionValue("config_file"));
    int numPings = Integer.parseInt(cmdArgs.getOptionValue("num_pings"));
    int maxPings = numPings;
    int sleepSecs = Integer.parseInt(cmdArgs.getOptionValue("sleep_secs"));

    sentryConfig.loadConfig();
    while (numPings > 0) {
        SentryPolicyService policyService = new SentryPolicyService(sentryConfig);
        try {
            policyService.listAllRoles(new User(System.getProperty("user.name")));
            LOG.info("Sentry Service ping succeeded.");
            System.exit(0);
        } catch (Exception e) {
            LOG.error(String.format("Error issing RPC to Sentry Service (attempt %d/%d): ",
                    maxPings - numPings + 1, maxPings), e);
            Thread.sleep(sleepSecs * 1000);
        }
        --numPings;
    }
    System.exit(1);
}

From source file:com.redhat.poc.jdg.bankofchina.function.TestCase413RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;//from  w ww . j a  v a 2s. c o  m
    Options options = new Options();
    options.addOption("s", true, "The start csv file number option");
    options.addOption("e", true, "The end csv file number option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("s")) {
            String start = commandLine.getOptionValue("s");
            if (start != null && start.length() > 0) {
                csvFileStart = Integer.parseInt(start);
            }
        }
        if (commandLine.hasOption("e")) {
            String end = commandLine.getOptionValue("e");
            if (end != null && end.length() > 0) {
                csvFileEnd = Integer.parseInt(end);
            }
        }
    }

    System.out.println(
            "%%%%%%%%%  csv ?, ?, ?(ms),"
                    + new Date().getTime());
    for (int i = csvFileStart; i <= csvFileEnd; i++) {
        new TestCase413RemoteMultiThreads(i).start();
    }
}

From source file:com.redhat.poc.jdg.bankofchina.function.TestCase411RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;// w  w w . j a v a2  s . c om
    Options options = new Options();
    options.addOption("s", true, "The start csv file number option");
    options.addOption("e", true, "The end csv file number option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("s")) {
            String start = commandLine.getOptionValue("s");
            if (start != null && start.length() > 0) {
                csvFileStart = Integer.parseInt(start);
            }
        }
        if (commandLine.hasOption("e")) {
            String end = commandLine.getOptionValue("e");
            if (end != null && end.length() > 0) {
                csvFileEnd = Integer.parseInt(end);
            }
        }
    }

    System.out.println(
            "%%%%%%%%%  csv ?, ?, ?(ms),"
                    + new Date().getTime());

    for (int i = csvFileStart; i <= csvFileEnd; i++) {
        new TestCase411RemoteMultiThreads(i).start();
    }
}

From source file:com.redhat.poc.jdg.bankofchina.function.TestCase412RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/*from w  w w . j  a v  a2s  .c o m*/
    Options options = new Options();
    options.addOption("s", true, "The start csv file number option");
    options.addOption("e", true, "The end csv file number option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("s")) {
            String start = commandLine.getOptionValue("s");
            if (start != null && start.length() > 0) {
                csvFileStart = Integer.parseInt(start);
            }
        }
        if (commandLine.hasOption("e")) {
            String end = commandLine.getOptionValue("e");
            if (end != null && end.length() > 0) {
                csvFileEnd = Integer.parseInt(end);
            }
        }
    }

    System.out.println(
            "%%%%%%%%%  csv ?, ?, ?(ms),"
                    + new Date().getTime());
    for (int i = csvFileStart; i <= csvFileEnd; i++) {
        new TestCase412RemoteMultiThreads(i).start();
    }
}

From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase52RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;//from w  ww .  j a v a2s. co m
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                writeThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadWriteTimes = Integer.parseInt(times);
            }
        }
    }
    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / writeThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + writeThreadNumbers + ", , ??, "
                    + threadWriteTimes + " ,?, ?(ms)," + new Date().getTime());
    for (int i = 0; i < writeThreadNumbers; i++) {
        new TestCase52RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}

From source file:com.xandrev.altafitcalendargenerator.Main.java

public static void main(String[] args) {
    CalendarPrinter printer = new CalendarPrinter();
    XLSExtractor extractor = new XLSExtractor();
    if (args != null && args.length > 0) {

        try {/*from w ww .j a va  2 s.  com*/
            Options opt = new Options();
            opt.addOption("f", true, "Filepath of the XLS file");
            opt.addOption("t", true, "Type name of activities");
            opt.addOption("m", true, "Month index");
            opt.addOption("o", true, "Output filename of the generated ICS");
            BasicParser parser = new BasicParser();
            CommandLine cliParser = parser.parse(opt, args);
            if (cliParser.hasOption("f")) {
                String fileName = cliParser.getOptionValue("f");
                LOG.debug("File name to be imported: " + fileName);

                String activityNames = cliParser.getOptionValue("t");
                LOG.debug("Activity type names: " + activityNames);

                ArrayList<String> nameList = new ArrayList<>();
                String[] actNames = activityNames.split(",");
                if (actNames != null) {
                    nameList.addAll(Arrays.asList(actNames));
                }
                LOG.debug("Sucessfully activities parsed: " + nameList.size());

                if (cliParser.hasOption("m")) {
                    String monthIdx = cliParser.getOptionValue("m");
                    LOG.debug("Month index: " + monthIdx);
                    int month = Integer.parseInt(monthIdx) - 1;

                    if (cliParser.hasOption("o")) {
                        String outputfilePath = cliParser.getOptionValue("o");
                        LOG.debug("Output file to be generated: " + monthIdx);

                        LOG.debug("Starting to extract the spreadsheet");
                        HashMap<Integer, ArrayList<TimeTrack>> result = extractor.importExcelSheet(fileName);
                        LOG.debug("Extracted the spreadsheet done");

                        LOG.debug("Starting the filter of the data");
                        HashMap<Date, String> cal = printer.getCalendaryByItem(result, nameList, month);
                        LOG.debug("Finished the filter of the data");

                        LOG.debug("Creating the ics Calendar");
                        net.fortuna.ical4j.model.Calendar calendar = printer.createICSCalendar(cal);
                        LOG.debug("Finished the ics Calendar");

                        LOG.debug("Printing the ICS file to: " + outputfilePath);
                        printer.saveCalendar(calendar, outputfilePath);
                        LOG.debug("Finished the ICS file to: " + outputfilePath);
                    }
                }
            }
        } catch (ParseException ex) {
            LOG.error("Error parsing the argument list: ", ex);
        }
    }
}

From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase51RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/*ww w . j  a  va  2s  .c om*/
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                readThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadReadTimes = Integer.parseInt(times);
            }
        }
    }

    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / readThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + readThreadNumbers + " ,, ???, "
                    + threadReadTimes + " ,?, ?(ms)," + new Date().getTime());

    for (int i = 0; i < readThreadNumbers; i++) {
        new TestCase51RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}

From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase531RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/*w w w . j  ava  2 s  .  c  o  m*/
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                readThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadReadTimes = Integer.parseInt(times);
            }
        }
    }

    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / readThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + readThreadNumbers + " ,, ???, "
                    + threadReadTimes + " ,?, ?(ms)," + new Date().getTime());

    for (int i = 0; i < readThreadNumbers; i++) {
        new TestCase531RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}