Class OptCfg

java.lang.Object
com.github.sttk.cliargs.OptCfg

public class OptCfg extends Object
Represents an option configuration for how to parse command line arguments. And this is also used when creating the help text for command line arguments.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Is the functional interface for the constructor parameters like named parameters.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final String
    Is the field to set a display string of the option argument(s) in a help text.
    Is the Optional object of a string list to specify default value(s) for when the command option is not given in command line arguments.
    final String
    Is the string field to set the description of the option which is used in a help text.
    final boolean
    Is the flag which allow the option to take option arguments.
    final boolean
    Is the flag which allow the option to take multiple option arguments.
    final List<String>
    Is the vector for specifying the option name and the aliases.
    final String
    Is the key to store option value(s) in the option map in a `Cmd` instance.
    final Validator
    Is the functional interface to validate the option argument(s).
  • Constructor Summary

    Constructors
    Constructor
    Description
    OptCfg(OptCfg.Param... params)
    Is the constructor that takes the variadic parameters of OptCfg.Param which can be specified like named parameters.
    OptCfg(String storeKey, List<String> names, boolean hasArg, boolean isArray, List<String> defaults, String desc, String argInHelp, Validator validator)
    Is the constructor that takes the all field values as parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    static OptCfg[]
    Makes an OptCfg array from the fields opt the option store with the annotation Opt.
    Returns the content string of this instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • storeKey

      public final String storeKey
      Is the key to store option value(s) in the option map in a `Cmd` instance.

      If this key is not specified or empty, the first element of the `names` field is used instead.

    • names

      public final List<String> names
      Is the vector for specifying the option name and the aliases.

      The order of the `names` in this array are used in a help text.

    • hasArg

      public final boolean hasArg
      Is the flag which allow the option to take option arguments.
    • isArray

      public final boolean isArray
      Is the flag which allow the option to take multiple option arguments.
    • defaults

      public final Optional<List<String>> defaults
      Is the Optional object of a string list to specify default value(s) for when the command option is not given in command line arguments.

      If this value is empty of the Optional, the default value(s) is not specified.

    • desc

      public final String desc
      Is the string field to set the description of the option which is used in a help text.
    • argInHelp

      public final String argInHelp
      Is the field to set a display string of the option argument(s) in a help text.

      An example of the display is like: -o, --option <value>.

    • validator

      public final Validator validator
      Is the functional interface to validate the option argument(s).

      If the option argument is invalid, this method throws a OptionArgIsInvalid exception.

  • Constructor Details

    • OptCfg

      public OptCfg(String storeKey, List<String> names, boolean hasArg, boolean isArray, List<String> defaults, String desc, String argInHelp, Validator validator)
      Is the constructor that takes the all field values as parameters.

      If storeKey is empty, it is set to first element of names. If names is empty or it's first element is empty, the first element is set to the value of storeKey.

      If type is not null but hasArg is false, hasArg is set to true forcely. Also, type is not null but converter is null, converter is set to a converter which convert a string to a specified type value.

      Parameters:
      storeKey - The store key.
      names - The option name and aliases.
      hasArg - True, if this option can take option arguments.
      isArray - True, if this option can take one or multiple option arguments.
      defaults - The default value(s).
      desc - The description of the option.
      argInHelp - The display of the option argument.
      validator - The validator to validate the option argument.
    • OptCfg

      public OptCfg(OptCfg.Param... params)
      Is the constructor that takes the variadic parameters of OptCfg.Param which can be specified like named parameters.

      If storeKey is empty, it is set to first element of names. If names is empty or it's first element is empty, the first element is set to the value of storeKey.

      If type is not null but hasArg is false, hasArg is set to true forcely. Also, type is not null but converter is null, converter is set to a converter which convert a string to a specified type value.

      Parameters:
      params - The variadic parameters of OptCfg.Param.
  • Method Details

    • toString

      public String toString()
      Returns the content string of this instance.
      Overrides:
      toString in class Object
      Returns:
      The content string of this instance.
    • makeOptCfgsFor

      public static OptCfg[] makeOptCfgsFor(Object optStore)
      Makes an OptCfg array from the fields opt the option store with the annotation Opt.

      About the process for OptCfg using Opt annotation, see the comment of Cmd.parseFor(java.lang.Object) method.

      Parameters:
      optStore - An option store object.
      Returns:
      An OptCfg array.