Example usage for org.apache.commons.cli2 CommandLine hasOption

List of usage examples for org.apache.commons.cli2 CommandLine hasOption

Introduction

In this page you can find the example usage for org.apache.commons.cli2 CommandLine hasOption.

Prototype

boolean hasOption(final Option option);

Source Link

Document

Detects the presence of an option in this CommandLine.

Usage

From source file:egat.cli.removeaction.RemoveActionCommandHandler.java

@Override
protected void handleAdditionalChildOptions(CommandLine commandLine) throws CommandProcessingException {
    if (commandLine.hasOption(actionOption)) {
        actionId = (String) commandLine.getValue(actionOption);
    }//from   w  w  w  . j  a  v a 2s . c o  m

    if (commandLine.hasOption(playerOption)) {
        playerId = (String) commandLine.getValue(playerOption);
    }
}

From source file:egat.cli.replicatordynamics.ReplicatorDynamicsCommandHandler.java

@Override
protected void handleAdditionalChildOptions(CommandLine commandLine) throws CommandProcessingException {
    verbose = commandLine.hasOption(verboseOption);

    tolerance = Double.parseDouble(commandLine.getValue(toleranceOption).toString());

    maxIteration = Integer.parseInt(commandLine.getValue(maxIterationOption).toString());
}

From source file:egat.cli.neresponse.NEResponseCommandHandler.java

@Override
protected void handleAdditionalChildOptions(CommandLine commandLine) throws CommandProcessingException {
    if (commandLine.hasOption(playerOption)) {
        playerId = (String) commandLine.getValue(playerOption);
    }/*  w  w w .j a v  a  2s.c  om*/

    profilePath = (String) commandLine.getValue(profilePathOption);

    gain = commandLine.hasOption(gainOption);
}

From source file:com.tamingtext.tagrecommender.CountStackOverflowTags.java

public boolean parseArgs(String[] args) {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
    Option helpOpt = DefaultOptionCreator.helpOption();

    Option inputFileOpt = obuilder.withLongName("inputFile").withRequired(true)
            .withArgument(abuilder.withName("inputFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The input file").withShortName("i").create();

    Option outputFileOpt = obuilder.withLongName("outputFile").withRequired(true)
            .withArgument(abuilder.withName("outputFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The output file").withShortName("o").create();

    Option limitOpt = obuilder.withLongName("limit").withRequired(false)
            .withArgument(abuilder.withName("limit").withMinimum(1).withMaximum(1).create())
            .withDescription("Emit this many of the most frequent tags").withShortName("l").create();

    Option cutoffOpt = obuilder.withLongName("cutoff").withRequired(false)
            .withArgument(abuilder.withName("cutoff").withMinimum(1).withMaximum(1).create())
            .withDescription("Drop tags with a count less than this number").withShortName("c").create();

    Group group = gbuilder.withName("Options").withOption(inputFileOpt).withOption(outputFileOpt)
            .withOption(limitOpt).withOption(cutoffOpt).create();

    try {/* ww  w . ja va  2s.c  om*/
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return false;
        }

        inputFile = new File((String) cmdLine.getValue(inputFileOpt));
        countFile = new File((String) cmdLine.getValue(outputFileOpt));

        if (cmdLine.hasOption(limitOpt)) {
            limit = Integer.parseInt((String) cmdLine.getValue(limitOpt));
        }

        if (cmdLine.hasOption(cutoffOpt)) {
            cutoff = Integer.parseInt((String) cmdLine.getValue(cutoffOpt));
        }

    } catch (OptionException e) {
        log.error("Command-line option Exception", e);
        CommandLineUtil.printHelp(group);
        return false;
    }

    validate();
    return true;
}

From source file:it.jnrpe.plugins.TestCommandLineParsing.java

@Test
public void testNoArgumentsOption() throws Exception {
    ClassLoader cl = TestCommandLineParsing.class.getClassLoader();
    PluginDefinition pluginDef = PluginRepositoryUtil.parseXmlPluginDefinition(cl,
            cl.getResourceAsStream("check_mysql_plugin.xml"));

    GroupBuilder gBuilder = new GroupBuilder();

    for (PluginOption po : pluginDef.getOptions()) {
        gBuilder = gBuilder.withOption(po.toOption());
    }/*  w w w .  ja  v  a2s . c o m*/

    Group group = gBuilder.create();
    Parser p = new Parser();
    p.setGroup(group);
    CommandLine cli = p.parse(new String[] { "--hostname", "$ARG1$", "--port", "$ARG2$", "--database", "$ARG3$",
            "--user", "$ARG4$", "--password", "$ARG5$", "--check-slave" });

    Assert.assertTrue(cli.hasOption("--check-slave"));
}

From source file:com.tamingtext.tagrecommender.TestStackOverflowTagger.java

public boolean parseArgs(String[] args) {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
    Option helpOpt = DefaultOptionCreator.helpOption();

    Option inputFileOpt = obuilder.withLongName("inputFile").withRequired(true)
            .withArgument(abuilder.withName("inputFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The input file").withShortName("i").create();

    Option countFileOpt = obuilder.withLongName("countFile").withRequired(true)
            .withArgument(abuilder.withName("countFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The tag count file").withShortName("c").create();

    Option outputFileOpt = obuilder.withLongName("outputFile").withRequired(true)
            .withArgument(abuilder.withName("outputFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The output file").withShortName("c").create();

    Option solrUrlOpt = obuilder.withLongName("solrUrl").withRequired(true)
            .withArgument(abuilder.withName("solrUrl").withMinimum(1).withMaximum(1).create())
            .withDescription("URL of the solr server").withShortName("s").create();

    Group group = gbuilder.withName("Options").withOption(inputFileOpt).withOption(countFileOpt)
            .withOption(outputFileOpt).withOption(solrUrlOpt).create();

    try {/* ww w . j  a va2  s  .c o m*/
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return false;
        }

        inputFile = new File((String) cmdLine.getValue(inputFileOpt));
        countFile = new File((String) cmdLine.getValue(countFileOpt));
        outputFile = new File((String) cmdLine.getValue(outputFileOpt));
        solrUrl = (String) cmdLine.getValue(solrUrlOpt);
        client = new TagRecommenderClient(solrUrl);
    } catch (OptionException e) {
        log.error("Command-line option Exception", e);
        CommandLineUtil.printHelp(group);
        return false;
    } catch (MalformedURLException e) {
        log.error("MalformedURLException", e);
        return false;
    }

    validate();
    return true;
}

From source file:com.tamingtext.tagrecommender.ExtractStackOverflowData.java

public boolean parseArgs(String[] args) {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
    Option helpOpt = DefaultOptionCreator.helpOption();

    Option inputFileOpt = obuilder.withLongName("inputFile").withRequired(true)
            .withArgument(abuilder.withName("inputFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The input file").withShortName("i").create();

    Option trainingOutputOpt = obuilder.withLongName("trainingOutputFile").withRequired(true)
            .withArgument(abuilder.withName("trainingOutputFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The training data output file").withShortName("tr").create();

    Option testOutputOpt = obuilder.withLongName("testOutputFile").withRequired(true)
            .withArgument(abuilder.withName("testOutputFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The test data output file").withShortName("te").create();

    Option trainingDataSizeOpt = obuilder.withLongName("trainingDataSize").withRequired(false)
            .withArgument(abuilder.withName("trainingDataSize").withMinimum(1).withMaximum(1).create())
            .withDescription("The number of questions to extract for training data").withShortName("trs")
            .create();/*  w  ww.  ja  v a 2s. co m*/

    Option testDataSizeOpt = obuilder.withLongName("testDataSize").withRequired(false)
            .withArgument(abuilder.withName("testDataSize").withMinimum(1).withMaximum(1).create())
            .withDescription("The number of questions to extract for training data").withShortName("tes")
            .create();

    Group group = gbuilder.withName("Options").withOption(inputFileOpt).withOption(trainingOutputOpt)
            .withOption(testOutputOpt).withOption(trainingDataSizeOpt).withOption(testDataSizeOpt).create();

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return false;
        }

        inputFile = new File((String) cmdLine.getValue(inputFileOpt));
        trainingOutputFile = new File((String) cmdLine.getValue(trainingOutputOpt));
        testOutputFile = new File((String) cmdLine.getValue(testOutputOpt));

        if (cmdLine.hasOption(trainingDataSizeOpt)) {
            trainingDataSize = Integer.parseInt((String) cmdLine.getValue(trainingDataSizeOpt));
        }

        if (cmdLine.hasOption(testDataSizeOpt)) {
            testDataSize = Integer.parseInt((String) cmdLine.getValue(testDataSizeOpt));
        }

    } catch (OptionException e) {
        log.error("Command-line option Exception", e);
        CommandLineUtil.printHelp(group);
        return false;
    }

    validate();
    return true;
}

From source file:egat.cli.AbstractGameCommandHandler.java

public void handleCommand(CommandLine commandLine) throws CommandProcessingException {

    if (commandLine.hasOption(getHelpOption())) {

        printHelp();/*from  ww w .  j a  va2  s  .c  om*/

    } else {

        boolean symmetricFlag = commandLine.hasOption(getSymmetricOption());

        boolean fileFlag = commandLine.hasOption(getFileOption());

        InputStream inputStream = System.in;

        if (fileFlag) {

            String filename = (String) commandLine.getValue(getFileOption());

            try {

                inputStream = new FileInputStream(filename);

            } catch (FileNotFoundException e) {

                throw new CommandProcessingException(e);

            }

        }

        handleAdditionalChildOptions(commandLine);

        processCommand(inputStream, symmetricFlag);

    }

}

From source file:com.wsc.myexample.decisionForest.MyBuildForest.java

public int init(String[] args) throws IOException, ClassNotFoundException, InterruptedException,
        InstantiationException, IllegalAccessException {

    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option dataOpt = obuilder.withLongName("data").withShortName("d").withRequired(true)
            .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create())
            .withDescription("Data path").create();

    Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true)
            .withArgument(abuilder.withName("dataset").withMinimum(1).withMaximum(1).create())
            .withDescription("Dataset path").create();

    Option selectionOpt = obuilder.withLongName("selection").withShortName("sl").withRequired(false)
            .withArgument(abuilder.withName("m").withMinimum(1).withMaximum(1).create())
            .withDescription("Optional, Number of variables to select randomly at each tree-node.\n"
                    + "For classification problem, the default is square root of the number of explanatory variables.\n"
                    + "For regression problem, the default is 1/3 of the number of explanatory variables.")
            .create();/* w ww .  j  a  va  2 s.  co  m*/

    Option noCompleteOpt = obuilder.withLongName("no-complete").withShortName("nc").withRequired(false)
            .withDescription("Optional, The tree is not complemented").create();

    Option minSplitOpt = obuilder.withLongName("minsplit").withShortName("ms").withRequired(false)
            .withArgument(abuilder.withName("minsplit").withMinimum(1).withMaximum(1).create())
            .withDescription("Optional, The tree-node is not divided, if the branching data size is "
                    + "smaller than this value.\nThe default is 2.")
            .create();

    Option minPropOpt = obuilder.withLongName("minprop").withShortName("mp").withRequired(false)
            .withArgument(abuilder.withName("minprop").withMinimum(1).withMaximum(1).create())
            .withDescription("Optional, The tree-node is not divided, if the proportion of the "
                    + "variance of branching data is smaller than this value.\n"
                    + "In the case of a regression problem, this value is used. "
                    + "The default is 1/1000(0.001).")
            .create();

    Option seedOpt = obuilder.withLongName("seed").withShortName("sd").withRequired(false)
            .withArgument(abuilder.withName("seed").withMinimum(1).withMaximum(1).create())
            .withDescription("Optional, seed value used to initialise the Random number generator").create();

    Option partialOpt = obuilder.withLongName("partial").withShortName("p").withRequired(false)
            .withDescription("Optional, use the Partial Data implementation").create();

    Option nbtreesOpt = obuilder.withLongName("nbtrees").withShortName("t").withRequired(true)
            .withArgument(abuilder.withName("nbtrees").withMinimum(1).withMaximum(1).create())
            .withDescription("Number of trees to grow").create();

    Option outputOpt = obuilder.withLongName("output").withShortName("o").withRequired(true)
            .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create())
            .withDescription("Output path, will contain the Decision Forest").create();

    Option helpOpt = obuilder.withLongName("help").withShortName("h").withDescription("Print out help")
            .create();

    Group group = gbuilder.withName("Options").withOption(dataOpt).withOption(datasetOpt)
            .withOption(selectionOpt).withOption(noCompleteOpt).withOption(minSplitOpt).withOption(minPropOpt)
            .withOption(seedOpt).withOption(partialOpt).withOption(nbtreesOpt).withOption(outputOpt)
            .withOption(helpOpt).create();

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption("help")) {
            CommandLineUtil.printHelp(group);
            return -1;
        }

        isPartial = cmdLine.hasOption(partialOpt);
        String dataName = cmdLine.getValue(dataOpt).toString();
        String datasetName = cmdLine.getValue(datasetOpt).toString();
        String outputName = cmdLine.getValue(outputOpt).toString();
        nbTrees = Integer.parseInt(cmdLine.getValue(nbtreesOpt).toString());

        if (cmdLine.hasOption(selectionOpt)) {
            m = Integer.parseInt(cmdLine.getValue(selectionOpt).toString());
        }
        complemented = !cmdLine.hasOption(noCompleteOpt);
        if (cmdLine.hasOption(minSplitOpt)) {
            minSplitNum = Integer.parseInt(cmdLine.getValue(minSplitOpt).toString());
        }
        if (cmdLine.hasOption(minPropOpt)) {
            minVarianceProportion = Double.parseDouble(cmdLine.getValue(minPropOpt).toString());
        }
        if (cmdLine.hasOption(seedOpt)) {
            seed = Long.valueOf(cmdLine.getValue(seedOpt).toString());
        }

        if (log.isDebugEnabled()) {
            log.debug("data : {}", dataName);
            log.debug("dataset : {}", datasetName);
            log.debug("output : {}", outputName);
            log.debug("m : {}", m);
            log.debug("complemented : {}", complemented);
            log.debug("minSplitNum : {}", minSplitNum);
            log.debug("minVarianceProportion : {}", minVarianceProportion);
            log.debug("seed : {}", seed);
            log.debug("nbtrees : {}", nbTrees);
            log.debug("isPartial : {}", isPartial);
        }

        dataPath = dataName;
        datasetPath = datasetName;
        outputPath = outputName;

    } catch (OptionException e) {
        log.error("Exception", e);
        CommandLineUtil.printHelp(group);
        return -1;
    }

    buildForest();

    return 0;
}

From source file:com.wsc.myexample.decisionForest.MyTestForest.java

public int init(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option inputOpt = DefaultOptionCreator.inputOption().create();

    Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true)
            .withArgument(abuilder.withName("dataset").withMinimum(1).withMaximum(1).create())
            .withDescription("Dataset path").create();

    Option modelOpt = obuilder.withLongName("model").withShortName("m").withRequired(true)
            .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create())
            .withDescription("Path to the Decision Forest").create();

    Option outputOpt = DefaultOptionCreator.outputOption().create();

    Option analyzeOpt = obuilder.withLongName("analyze").withShortName("a").withRequired(false).create();

    Option mrOpt = obuilder.withLongName("mapreduce").withShortName("mr").withRequired(false).create();

    Option helpOpt = DefaultOptionCreator.helpOption();

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(datasetOpt).withOption(modelOpt)
            .withOption(outputOpt).withOption(analyzeOpt).withOption(mrOpt).withOption(helpOpt).create();

    try {//  www. j ava 2s  . co  m
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption("help")) {
            CommandLineUtil.printHelp(group);
            return -1;
        }

        String dataName = cmdLine.getValue(inputOpt).toString();
        String datasetName = cmdLine.getValue(datasetOpt).toString();
        String modelName = cmdLine.getValue(modelOpt).toString();
        String outputName = cmdLine.hasOption(outputOpt) ? cmdLine.getValue(outputOpt).toString() : null;
        analyze = cmdLine.hasOption(analyzeOpt);
        useMapreduce = cmdLine.hasOption(mrOpt);

        if (log.isDebugEnabled()) {
            log.debug("inout     : {}", dataName);
            log.debug("dataset   : {}", datasetName);
            log.debug("model     : {}", modelName);
            log.debug("output    : {}", outputName);
            log.debug("analyze   : {}", analyze);
            log.debug("mapreduce : {}", useMapreduce);
        }

        dataPath = dataName;
        datasetPath = datasetName;
        modelPath = modelName;
        if (outputName != null) {
            outputPath = outputName;
        }
    } catch (OptionException e) {
        log.warn(e.toString(), e);
        CommandLineUtil.printHelp(group);
        return -1;
    }

    testForest();

    return 0;
}