org.wildfly.swarm.cli

## Class Option<T>

- java.lang.Object
- - org.wildfly.swarm.cli.Option<T>

-     public class Option<T>
      extends Object

  A single option specification.

  An option may have a short (single-dash) or long (double-dash) variant.

  Each option may optionally take a value, which may or may not be allowed to be separated from the option.

  For instance, if `valueMayBeSeparate(boolean)` is specified as false, then only `-Dwhatever` would be allowed, while `-D whatever` would not.

  Upon successful match, each `Option` has an `Option.Action` associated which is called with the value (if any) and the state-holding `CommandLine` object.

  Author:
    Bob McWhirter

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `Option.Action<T>` Callback functional interface for matched options.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Option()` Construct an empty option.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `displayHelp(PrintStream out)` Display formatted help associated with this option.
    `Option<T>` | `hasValue(String valueDescription)` Specify that this option takes an argument value.
    `Option<T>` | `then(Option.Action<T> action)` Associate an action with this option.
    `String` | `toString()`
    `static URL` | `toURL(String value)` Helper to attempt forming a URL from a String in a sensible fashion.
    `Option<T>` | `valueMayBeSeparate(boolean valueMayBeSeparate)` Indicate if the value to the option may be separated by whitespace.
    `Option<T>` | `withDefault(Supplier<T> supplier)` Specify a default value supplier for this option.
    `Option<T>` | `withDescription(String description)` Set a human-readable description of this option.
    `Option<T>` | `withLong(String longArg)` Specify a long (double-dash) variant.
    `Option<T>` | `withShort(Character shortArg)` Specify a short (single-dash) variant.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Option

          public Option()

      Construct an empty option.

  - ### Method Detail

    - #### then

          public Option<T> then(Option.Action<T> action)

      Associate an action with this option.
      Parameters:
        `action` - The action to call when matched.
      Returns:
        This `Option` object.

    - #### displayHelp

          public void displayHelp(PrintStream out)

      Display formatted help associated with this option.
      Parameters:
        `out` - The output stream to display the help upon.

    - #### withShort

          public Option<T> withShort(Character shortArg)

      Specify a short (single-dash) variant.

      A single character following a single dash, such as `-c`.

      Parameters:
        `shortArg` - The character.
      Returns:
        This `Option` object.

    - #### withLong

          public Option<T> withLong(String longArg)

      Specify a long (double-dash) variant.

      A string following a double-dash, such as `--help`.

      Parameters:
        `longArg` - The string (without dashes).
      Returns:
        This `Option` object.

    - #### withDescription

          public Option<T> withDescription(String description)

      Set a human-readable description of this option.
      Parameters:
        `description` - The description.
      Returns:
        This `Option` object.

    - #### hasValue

          public Option<T> hasValue(String valueDescription)

      Specify that this option takes an argument value.

      A non-null string passed to this method will be used to signify that this option may take an argument, and to describe its format.

      For instance a string of `name[=value]`

      would indicate that a `name` is expected, with an optional `value` which should follow an equal sign.
      Parameters:
        `valueDescription` -
      Returns:

    - #### valueMayBeSeparate

          public Option<T> valueMayBeSeparate(boolean valueMayBeSeparate)

      Indicate if the value to the option may be separated by whitespace. (defaults to `true`).

      In some cases, because of ambiguity, it may be required to indicate that an argument may not be separate from the option. If an argument is to be provided, it must immediately follow the option without whitespace.

      Parameters:
        `valueMayBeSeparate` - `true` (the default) if value may be separate, or `false` to indicate it must be conjoined.
      Returns:
        This `Option` object.

    - #### withDefault

          public Option<T> withDefault(Supplier<T> supplier)

      Specify a default value supplier for this option.
      Parameters:
        `supplier` - The supplier.
      Returns:
        This `Option` object.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### toURL

          public static URL toURL(String value)
                           throws MalformedURLException

      Helper to attempt forming a URL from a String in a sensible fashion.
      Parameters:
        `value` - The input string.
      Returns:
        The correct URL, if possible.
      Throws:
        `MalformedURLException`

Copyright © 2018 JBoss by Red Hat. All rights reserved.