Class ArgHandlerFlag

  • Direct Known Subclasses:
    ArgHandlerIgnore, ArgHandlerOverwrite

    public abstract class ArgHandlerFlag
    extends ArgHandler
    Argument handler for boolean flags that have no parameters. Supports toggling the boolean value on and off using -label and -nolabel tag variants and calculating a meaningful purpose including default value.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArgHandlerFlag()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addTagValue​(java.lang.String tag, boolean value)  
      abstract boolean getDefaultValue()
      Returns the default value that will appear in help messages.
      java.lang.String getHelpTag()
      The tag to display in help messages.
      java.lang.String getLabel()
      The root String that will be munged into -label and -nolabel variants for flag value toggling.
      java.lang.String getPurpose()  
      abstract java.lang.String getPurposeSnippet()
      Returns a description that will be mixed together with default value to come up with the overall flag purpose.
      java.lang.String getTag()
      The primary tag matched by this argument handler.
      java.lang.String[] getTagArgs()
      A list of words representing the arguments in help text.
      java.lang.String[] getTags()
      The set of tags matched by this argument handler.
      (package private) boolean getValueByTag​(java.lang.String tag)  
      int handle​(java.lang.String[] args, int startIndex)
      Attempts to process one flag or "extra" command-line argument (that appears without a flag).
      boolean isRequired()  
      abstract boolean setFlag​(boolean value)
      Takes the explicitly provided value and propagates it into whatever option settings this flag controls.
      • Methods inherited from class java.lang.Object

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

      • ArgHandlerFlag

        public ArgHandlerFlag()
    • Method Detail

      • addTagValue

        protected void addTagValue​(java.lang.String tag,
                                   boolean value)
      • getDefaultValue

        public abstract boolean getDefaultValue()
        Returns the default value that will appear in help messages.
      • getHelpTag

        public java.lang.String getHelpTag()
        Description copied from class: ArgHandler
        The tag to display in help messages.
        Overrides:
        getHelpTag in class ArgHandler
      • getLabel

        public java.lang.String getLabel()
        The root String that will be munged into -label and -nolabel variants for flag value toggling. Should follow the verb[Adjective]Noun naming pattern. For example:
      • getPurpose

        public final java.lang.String getPurpose()
        Specified by:
        getPurpose in class ArgHandler
      • getPurposeSnippet

        public abstract java.lang.String getPurposeSnippet()
        Returns a description that will be mixed together with default value to come up with the overall flag purpose.
      • getTag

        public final java.lang.String getTag()
        The primary tag matched by this argument handler.
        Specified by:
        getTag in class ArgHandler
      • getTagArgs

        public java.lang.String[] getTagArgs()
        Description copied from class: ArgHandler
        A list of words representing the arguments in help text.
        Specified by:
        getTagArgs in class ArgHandler
      • getTags

        public final java.lang.String[] getTags()
        Description copied from class: ArgHandler
        The set of tags matched by this argument handler. By default includes just the one primary tag mentioned in getTag() but can be overridden to provide broader matching.
        Overrides:
        getTags in class ArgHandler
      • getValueByTag

        boolean getValueByTag​(java.lang.String tag)
      • handle

        public int handle​(java.lang.String[] args,
                          int startIndex)
        Description copied from class: ArgHandler
        Attempts to process one flag or "extra" command-line argument (that appears without a flag).
        Specified by:
        handle in class ArgHandler
        Parameters:
        args - the arguments passed in to main()
        startIndex - an index into args indicating the first argument to use. If this is a handler for a flag argument. Otherwise it's the index of the "extra" argument.
        Returns:
        the number of additional arguments consumed, not including the flag or extra argument. Alternately, returns -1 if the argument cannot be used. This will causes the program to abort and usage to be displayed.
      • setFlag

        public abstract boolean setFlag​(boolean value)
        Takes the explicitly provided value and propagates it into whatever option settings this flag controls.
        Parameters:
        value - the new value for the flag.
        Returns:
        whether the assignment was valid.