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

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

Introduction

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

Prototype

BasicParser

Source Link

Usage

From source file:genql.CLIRunner.java

public static void main(String[] args) {
    Options options = setupOptions();/*from   w  w  w  . java  2s .co  m*/
    CommandLineParser parser = new BasicParser();
    try {
        //            for (int i = 0; i < args.length; i++) {
        //                System.out.println(args[i]);
        //            }
        CommandLine line = parser.parse(options, args);
        if (line.hasOption('e')) {
            isEval = true;
        }
        if (line.hasOption('g')) {
            isGen = true;
        }
        if (line.hasOption('d')) {
            corpusDir = line.getOptionValue('d');
        }
        if (line.hasOption('n')) {
            qcount = Integer.parseInt(line.getOptionValue('n'));
        } else {
            qcount = 10;
        }
        if (line.hasOption('o')) {
            outputFile = line.getOptionValue('o');
        }
        if (line.hasOption('g')) {
            groundTruthQueryFile = line.getOptionValue('g');
        }
        if (line.hasOption('q')) {
            generatedQueryFile = line.getOptionValue('q');
        }
        if (line.hasOption('m')) {
            min_query_len = Integer.parseInt(line.getOptionValue('m'));
        } else {
            min_query_len = 2;
        }
        if (line.hasOption('x')) {
            max_query_len = Integer.parseInt(line.getOptionValue('x'));
        } else {
            max_query_len = 7;
        }
        if (line.hasOption('h')) {
            printHelpAndExit(options);
        }

        if (isGen) {
            MainApp.gen(corpusDir, outputFile, qcount, min_query_len, max_query_len);
        } else if (isEval) {
            final String intermediateResults = corpusDir + "/temp";
            new File(intermediateResults).mkdir();
            MainApp.eval(corpusDir, generatedQueryFile, groundTruthQueryFile, intermediateResults,
                    min_query_len, max_query_len);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println("Unexpected exception: " + ex.getMessage());
        System.exit(1);
    }
}

From source file:com.discursive.jccook.cmdline.CliBasicExample.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new BasicParser();

    Options options = new Options();
    options.addOption("h", "help", false, "Print this usage information");
    options.addOption("v", "verbose", false, "Print out VERBOSE debugging information");
    options.addOption("f", "file", true, "File to save program output to");

    CommandLine commandLine = parser.parse(options, args);

    boolean verbose = false;
    String file = "";

    if (commandLine.hasOption('h')) {
        System.out.println("Help Message");
        System.exit(0);//from   w  w  w  .  ja  v  a2  s . com
    }

    if (commandLine.hasOption('v')) {
        verbose = true;
    }

    if (commandLine.hasOption('f')) {
        file = commandLine.getOptionValue('f');
    }

    System.exit(0);
}

From source file:com.discursive.jccook.cmdline.CliComplexExample.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new BasicParser();

    Options options = new Options();
    options.addOption("h", "help", false, "Print this usage information");
    options.addOption("v", "verbose", false, "Print out VERBOSE debugging information");
    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(OptionBuilder.hasArg(true).create('f'));
    optionGroup.addOption(OptionBuilder.hasArg(true).create('m'));
    options.addOptionGroup(optionGroup);

    CommandLine commandLine = parser.parse(options, args);

    boolean verbose = false;
    String file = "";
    String mail = "";

    if (commandLine.hasOption('h')) {
        System.out.println("Help Message");
        System.exit(0);//from   w w  w  .ja  v  a 2  s. c  om
    }

    if (commandLine.hasOption('v')) {
        verbose = true;
    }

    if (commandLine.hasOption('f')) {
        file = commandLine.getOptionValue('f');
    } else if (commandLine.hasOption('m')) {
        mail = commandLine.getOptionValue('m');
    }

    System.exit(0);
}

From source file:com.jbrisbin.vcloud.cache.Bootstrap.java

public static void main(String[] args) {

    CommandLineParser parser = new BasicParser();
    CommandLine cmdLine = null;/*from   w  ww  .  j  a v  a2s  .c o  m*/
    try {
        cmdLine = parser.parse(opts, args);
    } catch (ParseException e) {
        log.error(e.getMessage(), e);
    }

    String configFile = "/etc/cloud/async-cache.xml";
    if (null != cmdLine) {
        if (cmdLine.hasOption('c')) {
            configFile = cmdLine.getOptionValue('c');
        }
    }

    ApplicationContext context = new FileSystemXmlApplicationContext(configFile);
    RabbitMQAsyncCacheProvider cacheProvider = context.getBean(RabbitMQAsyncCacheProvider.class);
    while (cacheProvider.isActive()) {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e);
        }
    }

}

From source file:edu.freiburg.dbis.rdd.RddExtractor.java

/**
 * @param args//w w w .j  av a  2s . c  o m
 */
public static void main(String[] args) {
    String Classname = RddExtractor.class.getName();
    // Creating and parsing commandline options
    Options options = createOptions();
    CommandLineParser parser = new BasicParser();
    HelpFormatter help = new HelpFormatter();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            help.printHelp(Classname, options);
            return;
        }
        // XOR (either input-file or sparql-endpoint) --> Throw error if it is the same
        if (cmd.hasOption("i") == cmd.hasOption("e")) {
            help.printHelp(Classname, options);
            System.err.println(
                    "Use either the the option to read from an input file or (XOR) the option to send queries against an SPARQL Endpoint");
            return;
        }
        // the graph variable can only be used with the sparql-enpoint
        if ((cmd.hasOption("g") == true) && (cmd.hasOption("e") == false)) {
            help.printHelp(Classname, options);
            System.err.println(
                    "The graph variable can only be used when sending queries against a SPARQL Endpoint");
            return;
        }

    } catch (ParseException e) {
        help.printHelp(Classname, options);
        System.err.println("Command line parsing failed. Reason: " + e.getMessage());
        return;
    }

    String INPUT_FILE = cmd.getOptionValue("i");
    String OUTPUT_FILE = cmd.getOptionValue("o");
    String ENDPOINTURL = cmd.getOptionValue("e");
    String VIRTUOSO_GRAPH_NAME = cmd.getOptionValue("g");
    String WA = cmd.getOptionValue("w");
    String propertyFile = "src/main/resources/log4j.properties2";
    if (cmd.hasOption("v")) {
        propertyFile = "src/main/resources/log4j.properties";
    } else if (cmd.hasOption("l")) {
        propertyFile = cmd.getOptionValue("l");
    }
    //      String propertyFile = (cmd.hasOption("l")) ? cmd.getOptionValue("l") : "src/main/resources/log4j.properties2";

    PropertyConfigurator.configure(propertyFile);

    logger.debug("INPUT FILE  : " + INPUT_FILE);
    logger.debug("OUTPUT FILE : " + OUTPUT_FILE);
    logger.debug("ENDPOINT URL: " + ENDPOINTURL);
    logger.debug("GRAPH NAME  : " + VIRTUOSO_GRAPH_NAME);
    logger.debug("WORLD ASSUMP: " + WA);

    long start = System.currentTimeMillis();
    long end = 0;
    logger.info("Starting The Generator");
    Backend back = new Backend(INPUT_FILE, OUTPUT_FILE, ENDPOINTURL, VIRTUOSO_GRAPH_NAME, WA);
    end = System.currentTimeMillis();
    logger.info("Runtime of Generator in ms: " + (end - 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 {/* w  ww.j a  va2  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.util.GenerateUserIdCsv.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;//w  w w  .  j  a  va  2s  . com
    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.epitech.oliver_f.astextexls.MainClass.java

public static void main(String[] args) {
    initalizeOption();//from  ww w .j  a  v  a  2 s. co m
    CommandLineParser parser = new BasicParser();
    CommandLine cl = null;
    try {
        cl = parser.parse(options, args);
    } catch (ParseException ex) {
        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (cl != null && cl.hasOption("help")) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("astexte script", options);
    }
    if (cl.hasOption("folder") && cl.hasOption("file")) {
        launchWriteAndRead(cl.getOptionValue("folder"), cl.getOptionValue("file"));
        System.out.println("OK");

    } else {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("astexte script", options);
    }
    launch(args);
}

From source file:graphgen.GraphGen.java

/**
 * @param args the command line arguments
 *///from w w w  .  ja  v  a 2s.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:com.adavr.player.Launcher.java

public static void main(String[] args) {
    CommandLine cl;// w ww . j  av  a  2  s.c om
    try {
        cl = new BasicParser().parse(OPTIONS, args);
    } catch (ParseException ex) {
        showUsage();
        return;
    }

    if (cl.hasOption("help")) {
        showUsage();
        return;
    }

    ApplicationContext appCtx = (ApplicationContext) loadClass(cl.getOptionValue("context"));
    if (appCtx == null) {
        System.out.println("Failed to load App Context");
        appCtx = new VLCApplication();
    }
    if (cl.hasOption("source")) {
        String src = cl.getOptionValue("source");
        appCtx.getMediaContext().setMedia(src);
    }

    Application application = new Application(appCtx);
    application.setVSync(cl.hasOption("vsync"));
    if (cl.hasOption("factory")) {
        String className = cl.getOptionValue("factory");
        HMDRenderContextFactory factory = (HMDRenderContextFactory) loadClass(className);
        if (factory != null) {
            application.setHMDRenderContextFactory(factory);
        }
    }

    application.run();
}