Class CmdArgOption<T>

java.lang.Object
com.github.hypfvieh.cli.parser.CmdArgOption<T>
Type Parameters:
T - data type of the option

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

Sample Usage:
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); // ... }

Since:
1.0.0 - 2022-04-19
Author:
David M., Markus S.
  • 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
    • getPossibleValues

      public Map<T,String> getPossibleValues()
      A map containing all values (and description) allowed for this option.
      Returns:
      Map, maybe empty never 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