Class BaseArgument

  • Direct Known Subclasses:
    Argument, BaseOption, SubCommandSet

    public abstract class BaseArgument
    extends java.lang.Object
    Arguments are part of the args list that is not designated with an option name. E.g. files to read etc. Since a single program can have multiple arguments, it's handled as a 'first accepted'. If the argument parsing hits a non '-' prefixed string, or has passed the 'stop' option ('--'), it will try to parse it as an argument. It will go through the available arguments until one has consumed it by returning > 0 on apply(ArgumentList).
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected BaseArgument​(java.lang.String name, java.lang.String usage, java.lang.String defaultValue, boolean repeated, boolean required, boolean hidden)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract int apply​(ArgumentList args)
      Try to apply to the argument.
      java.lang.String getDefaultValue()
      A default value descriptor.
      java.lang.String getName()
      The argument name.
      abstract java.lang.String getPrefix()
      Prefix part of the usage usage message.
      abstract java.lang.String getSingleLineUsage()
      Get the argument's single line usage string.
      java.lang.String getUsage()
      The argument usage description.
      boolean isHidden()
      True if the argument should be hidden by default.
      boolean isRepeated()
      If the argument can be repeated (for arguments means to be multi-valued).
      boolean isRequired()
      If the argument is required (must be set).
      abstract void validate()
      Called on all the arguments after the parsing is done to validate if all requirements have been passed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BaseArgument

        protected BaseArgument​(java.lang.String name,
                               java.lang.String usage,
                               java.lang.String defaultValue,
                               boolean repeated,
                               boolean required,
                               boolean hidden)
    • Method Detail

      • getName

        public java.lang.String getName()
        The argument name. This is visible in the single-line and usage print-outs.
        Returns:
        The argument name.
      • getUsage

        public java.lang.String getUsage()
        The argument usage description.
        Returns:
        The usdage description.
      • getDefaultValue

        public java.lang.String getDefaultValue()
        A default value descriptor.
        Returns:
        The default value or null.
      • isRepeated

        public boolean isRepeated()
        If the argument can be repeated (for arguments means to be multi-valued).
        Returns:
        True if the argument is repeated.
      • isRequired

        public boolean isRequired()
        If the argument is required (must be set).
        Returns:
        True if the argument is required.
      • isHidden

        public boolean isHidden()
        True if the argument should be hidden by default. Passing showHidden to printUsage will print the option. It will be hidden from singleLineUsage regardless.
        Returns:
        If the argument is hidden.
      • getSingleLineUsage

        public abstract java.lang.String getSingleLineUsage()
        Get the argument's single line usage string.
        Returns:
        The single-line usage string.
      • getPrefix

        public abstract java.lang.String getPrefix()
        Prefix part of the usage usage message.
        Returns:
        The usage prefix.
      • validate

        public abstract void validate()
                               throws ArgumentException
        Called on all the arguments after the parsing is done to validate if all requirements have been passed. Should throw an ArgumentException if is did not validate with the appropriate error message.
        Throws:
        ArgumentException
      • apply

        public abstract int apply​(ArgumentList args)
        Try to apply to the argument. The method shoud return 0 if the argument is rejected, otherwise the number of argument strings that was consumed.
        Parameters:
        args - The argument list.
        Returns:
        The number of args consumed.