Example usage for org.apache.commons.cli2.validation NumberValidator setMinimum

List of usage examples for org.apache.commons.cli2.validation NumberValidator setMinimum

Introduction

In this page you can find the example usage for org.apache.commons.cli2.validation NumberValidator setMinimum.

Prototype

public void setMinimum(Number minimum) 

Source Link

Document

Specify the minimum value allowed for an argument value.

Usage

From source file:it.jnrpe.client.JNRPEClient.java

/**
 * Configures the command line parser./*from www. j  a v a 2s  .  c  o m*/
 * 
 * @return The command line parser configuration
 */
private static Group configureCommandLine() {
    DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
    ArgumentBuilder aBuilder = new ArgumentBuilder();
    GroupBuilder gBuilder = new GroupBuilder();

    DefaultOption nosslOption = oBuilder.withLongName("nossl").withShortName("n")
            .withDescription("Do no use SSL").create();

    DefaultOption weakSslOption = oBuilder.withLongName("weakCiherSuites").withShortName("w")
            .withDescription("Enable weak cipher suites").create();

    DefaultOption unknownOption = oBuilder.withLongName("unknown").withShortName("u")
            .withDescription("Make socket timeouts return an UNKNOWN state instead of CRITICAL").create();

    DefaultOption hostOption = oBuilder.withLongName("host").withShortName("H")
            .withDescription("The address of the host running the JNRPE/NRPE daemon")
            .withArgument(aBuilder.withName("host").withMinimum(1).withMaximum(1).create()).create();

    NumberValidator positiveInt = NumberValidator.getIntegerInstance();
    positiveInt.setMinimum(0);
    DefaultOption portOption = oBuilder.withLongName("port").withShortName("p")
            .withDescription("The port on which the daemon is running (default=5666)")
            .withArgument(aBuilder.withName("port").withMinimum(1).withMaximum(1)
                    .withDefault(Long.valueOf(DEFAULT_PORT)).withValidator(positiveInt).create())
            .create();

    DefaultOption timeoutOption = oBuilder.withLongName("timeout").withShortName("t")
            .withDescription("Number of seconds before connection times out (default=10)")
            .withArgument(aBuilder.withName("timeout").withMinimum(1).withMaximum(1)
                    .withDefault(Long.valueOf(DEFAULT_TIMEOUT)).withValidator(positiveInt).create())
            .create();

    DefaultOption commandOption = oBuilder.withLongName("command").withShortName("c")
            .withDescription("The name of the command that the remote daemon should run")
            .withArgument(aBuilder.withName("command").withMinimum(1).withMaximum(1).create()).create();

    DefaultOption argsOption = oBuilder.withLongName("arglist").withShortName("a").withDescription(
            "Optional arguments that should be passed to the command.  Multiple arguments should be separated by "
                    + "a space (' '). If provided, this must be the last option supplied on the command line.")
            .withArgument(aBuilder.withName("arglist").withMinimum(1).create()).create();

    DefaultOption helpOption = oBuilder.withLongName("help").withShortName("h")
            .withDescription("Shows this help").create();

    Group executionOption = gBuilder.withOption(nosslOption).withOption(weakSslOption).withOption(unknownOption)
            .withOption(hostOption).withOption(portOption).withOption(timeoutOption).withOption(commandOption)
            .withOption(argsOption).create();

    return gBuilder.withOption(executionOption).withOption(helpOption).withMinimum(1).withMaximum(1).create();
}