Class CmdArgOption<T>

java.lang.Object
com.github.hypfvieh.cli.parser.CmdArgOption<T>

public final class CmdArgOption<T> extends Object
Describes a command-line option.
Options are created using the associated CmdArgOption.Builder.

Sample Usage:

 {@code
    CmdArgOption<ITransformer> optImpl = CmdArgOption.builder(ITransformer.class)
            .name("transformerClass")
            .description("FQCN of transformer implementation")
            .required(true)
            .build();

    CommandLine cli = new CommandLine().addOptions(optImpl);
    // ...
    cli.parse(args);

    if (cli.hasOption(optImpl)) {
        ITransformer transformer = cli.getArg(optImpl);
        // ...
    }
  </pre>

 @param <T> data type of the option

 @author David M.
 @author Markus S.
 @since 1.0.0 - 2022-04-19
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builder for a command-line option.
    The builder guarantees the option it builds is valid.
    At a minimum an option requires a name.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a builder for a new option without value (therefore default value not permitted).
    static <T> CmdArgOption.Builder<T>
    builder(Class<T> _dataType)
    Returns a builder for a new option with the specified data type.
    As the data type is specified, the option must have a value (and may have a default value).
    boolean
    equals(Object _obj)
     
    Returns the type of data to create from argument.
    Returns the default value for this option (when option was not set).
    Returns the description text for this option.
    Returns the long name of this option
    Returns the short name of this option.
    int
     
    boolean
    Flag to signal if the option requires a value.
    boolean
    Flag to signal that this option is optional.
    boolean
    Flag to allow the option to be repeated multiple times.
    boolean
    Flag to signal if this option is required.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • getName

      public String getName()
      Returns the long name of this option
      Returns:
      String, maybe null or empty
    • getShortName

      public String getShortName()
      Returns the short name of this option.
      Returns:
      String, maybe empty or null
    • getDescription

      public String getDescription()
      Returns the description text for this option.
      Returns:
      String, maybe empty or null
    • isRequired

      public boolean isRequired()
      Flag to signal if this option is required.
      Returns:
      true if required
    • isRepeatable

      public boolean isRepeatable()
      Flag to allow the option to be repeated multiple times.
      Returns:
      true if repeatable
    • isOptional

      public boolean isOptional()
      Flag to signal that this option is optional.
      Returns:
      true if optional
    • hasValue

      public boolean hasValue()
      Flag to signal if the option requires a value.
      Returns:
      true if value required
    • getDefaultValue

      public Object getDefaultValue()
      Returns the default value for this option (when option was not set).
      Returns:
      default value, maybe null
    • getDataType

      public Class<?> getDataType()
      Returns the type of data to create from argument.
      Returns:
      class, maybe null
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object _obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static <T> CmdArgOption.Builder<T> builder(Class<T> _dataType)
      Returns a builder for a new option with the specified data type.
      As the data type is specified, the option must have a value (and may have a default value).
      Type Parameters:
      T - data type of the option
      Parameters:
      _dataType - data type of option
      Returns:
      builder
    • builder

      public static CmdArgOption.Builder<Void> builder()
      Returns a builder for a new option without value (therefore default value not permitted).
      Returns:
      builder