Interface ArgsParser

  • All Superinterfaces:
    ArgsParserMixin<ArgsParser>, org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<ArgsParser>, org.refcodes.mixin.DescriptionAccessor.DescriptionMutator, org.refcodes.mixin.NameAccessor.NameBuilder<ArgsParser>, org.refcodes.mixin.NameAccessor.NameMutator, org.refcodes.component.Resetable, RootConditionAccessor, org.refcodes.mixin.TitleAccessor.TitleBuilder<ArgsParser>, org.refcodes.mixin.TitleAccessor.TitleMutator
    All Known Implementing Classes:
    ArgsParserImpl


    public interface ArgsParser
    extends ArgsParserMixin<ArgsParser>, org.refcodes.mixin.TitleAccessor.TitleMutator, org.refcodes.mixin.TitleAccessor.TitleBuilder<ArgsParser>, org.refcodes.mixin.NameAccessor.NameMutator, org.refcodes.mixin.NameAccessor.NameBuilder<ArgsParser>, org.refcodes.mixin.DescriptionAccessor.DescriptionMutator, org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<ArgsParser>, org.refcodes.component.Resetable, RootConditionAccessor
    The ArgsParser provides means for parsing command line arguments and constructing a command line utility's help output.
    • Method Detail

      • evalArgs

        java.util.List<? extends Operand<?>> evalArgs​(java.lang.String[] aArgs)
                                               throws UnknownArgsException,
                                                      AmbiguousArgsException,
                                                      SuperfluousArgsException,
                                                      ParseArgsException
        Evaluates the provided command line arguments and determines the according values by evaluating the root Condition. In case of parsing failure, an according exception is thrown. ATTENTION: This method tests(!) for superfluous command line arguments being passed; e.g. command line arguments not being evaluated by any of the Syntaxable instance being traversed starting at the root Condition will be reported. Business logic therefore should invoke this root node's evalArgs(String[]) method instead of a Condition's Syntaxable.parseArgs(String[]) method; as ignoring superfluous command line arguments will cause unexpected behavior from the point of view of the invoker.
        Parameters:
        aArgs - The command line arguments to be evaluated.
        Returns:
        The list of evaluated command line arguments being instances of the Operand interfaces or its sub-types.
        Throws:
        UnknownArgsException - Thrown in case not one command line argument matched regarding the provided args vs. the expected args.
        AmbiguousArgsException - Thrown in case at least one command line argument is ambiguous regarding expected args vs. provided args.
        SuperfluousArgsException - Thrown in case there were arguments found not being used (superfluous arguments).
        ParseArgsException - Thrown in case the provided command line arguments do not respect the required syntax or cannot be converted to the required type
      • evalArgs

        default java.util.List<? extends Operand<?>> evalArgs​(java.util.List<java.lang.String> aArgs)
                                                       throws UnknownArgsException,
                                                              AmbiguousArgsException,
                                                              SuperfluousArgsException,
                                                              ParseArgsException
        Same as evalArgs(String[]) with the difference that the elements representing the arguments are passed as a list instead of an array.
        Parameters:
        aArgs - The command line arguments to be evaluated.
        Returns:
        The list of evaluated command line arguments being instances of the Operand interfaces or its sub-types.
        Throws:
        UnknownArgsException - Thrown in case not one command line argument matched regarding the provided args vs. the expected args.
        AmbiguousArgsException - Thrown in case at least one command line argument is ambiguous regarding expected args vs. provided args.
        SuperfluousArgsException - Thrown in case there were arguments found not being used (superfluous arguments).
        ParseArgsException - Thrown in case the provided command line arguments do not respect the required syntax or cannot be converted to the required type
      • withEvalArgs

        default ArgsParser withEvalArgs​(java.util.List<java.lang.String> aArgs)
                                 throws UnknownArgsException,
                                        AmbiguousArgsException,
                                        SuperfluousArgsException,
                                        ParseArgsException
        Same as evalArgs(List) with the difference that this class's instance being invoked is returned as of the builder pattern.
        Parameters:
        aArgs - The command line arguments to be evaluated.
        Returns:
        This invoked instance as of the builder pattern to chain method calls.
        Throws:
        UnknownArgsException - Thrown in case not one command line argument matched regarding the provided args vs. the expected args.
        AmbiguousArgsException - Thrown in case at least one command line argument is ambiguous regarding expected args vs. provided args.
        SuperfluousArgsException - Thrown in case there were arguments found not being used (superfluous arguments).
        ParseArgsException - Thrown in case the provided command line arguments do not respect the required syntax or cannot be converted to the required type
      • getRootCondition

        Condition getRootCondition​()
        The root condition is the starting point node of a Syntaxable hierarchy to be traversed when determining the syntax for command line arguments or when evaluating the command line arguments. Retrieves the rootCondition from the rootCondition property.
        Specified by:
        getRootCondition in interface RootConditionAccessor
        Returns:
        The root Condition in which's syntax this parser is based.
      • setBannerFont

        void setBannerFont​(org.refcodes.textual.Font aBannerFont)
        Sets the banner font.
        Parameters:
        aBannerFont - the new banner font
      • setBannerFontPalette

        void setBannerFontPalette​(char[] aColorPalette)
        Sets the banner font palette.
        Parameters:
        aColorPalette - the new banner font palette
      • setLineBreak

        void setLineBreak​(java.lang.String aLineBreak)
        Set the console's line break. A setting of null makes the instance use the SystemUtility.getLineBreak() value.
        Parameters:
        aLineBreak - the new line break
      • setConsoleWidth

        void setConsoleWidth​(int aConsoleWidth)
        Set the console with. A setting of "-1" makes the instance use the SystemUtility.getTerminalWidth() value, i.e. the console width is set automatically to be the width of your terminal.
        Parameters:
        aConsoleWidth - The width to set or -1 to let the parser automatically determine the console width.
      • setMaxConsoleWidth

        void setMaxConsoleWidth​(int aMaxConsoleWidth)
        Set the maximum console width to use in case the console width is greater than the maximum you want. This is most useful when the console width is determined automatically to be the width of your terminal.
        Parameters:
        aMaxConsoleWidth - the new max console width
      • setStandardOut

        void setStandardOut​(java.io.PrintStream aStandardOut)
        Set the standard out PrintStream and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aStandardOut - The standard out PrintStream to set.
      • setErrorOut

        void setErrorOut​(java.io.PrintStream aErrorOut)
        Set the error out PrintStream and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aErrorOut - The error out PrintStream to set.
      • setLicenseNote

        void setLicenseNote​(java.lang.String aLicenseNote)
        Set the license note used by the printHelp() method when writing out the licensing conditions.
        Parameters:
        aLicenseNote - The license note printed out by the printHelp() method.
      • setUsageLabel

        void setUsageLabel​(java.lang.String aUsageLabel)
        Set the usage label used by the printHelp() method when writing out the syntax.
        Parameters:
        aUsageLabel - The usage label printed out by the printHelp() method.
      • setCopyrightNote

        void setCopyrightNote​(java.lang.String aCopyrightNote)
        Set the copyright note used by the printHelp() method when writing out the copyright claim and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aCopyrightNote - The license note printed out by the printHelp() method.
      • setSeparatorChar

        void setSeparatorChar​(char aSeparatorChar)
        Set the character to be used when printing a separator line with the printSeparatorLn() method.
        Parameters:
        aSeparatorChar - The character used by the printSeparatorLn() method when printing out the line of characters..
      • withBannerFont

        default ArgsParser withBannerFont​(org.refcodes.textual.Font aBannerFont)
        With banner font.
        Parameters:
        aBannerFont - the banner font
        Returns:
        the args parser
      • withBannerFontPalette

        default ArgsParser withBannerFontPalette​(char[] aColorPalette)
        With banner font palette.
        Parameters:
        aColorPalette - the color palette
        Returns:
        the args parser
      • withLineBreak

        default ArgsParser withLineBreak​(java.lang.String aLineBreak)
        Set the console's line break. A setting of null makes the instance use the SystemUtility.getLineBreak() value.
        Parameters:
        aLineBreak - the line break
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withConsoleWidth

        default ArgsParser withConsoleWidth​(int aConsoleWidth)
        Set the console with. A setting of "-1" makes the instance use the SystemUtility.getTerminalWidth() value.
        Parameters:
        aConsoleWidth - The width to set.
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withMaxConsoleWidth

        default ArgsParser withMaxConsoleWidth​(int aMaxConsoleWidth)
        Set the maximum console width to use in case the console width is greater than the maximum you want. This is most useful when the console width is determined automatically to be the width of your terminal.
        Parameters:
        aMaxConsoleWidth - the max console width
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withStandardOut

        default ArgsParser withStandardOut​(java.io.PrintStream aStandardOut)
        Set the standard out PrintStream and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aStandardOut - The standard out PrintStream to set.
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withErrorOut

        default ArgsParser withErrorOut​(java.io.PrintStream aErrorOut)
        Set the error out PrintStream and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aErrorOut - The error out PrintStream to set.
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withSyntaxNotation

        default ArgsParser withSyntaxNotation​(SyntaxNotation aSyntaxNotation)
        Set the SyntaxNotation and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aSyntaxNotation - The SyntaxNotation to set.
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withLicenseNote

        default ArgsParser withLicenseNote​(java.lang.String aLicenseNote)
        Set the license note used by the printHelp() method when writing out the licensing conditions and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aLicenseNote - The license note printed out by the printHelp() method.
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withUsageLabel

        default ArgsParser withUsageLabel​(java.lang.String aUsageLabel)
        Set the usage label used by the printHelp() method when writing out the syntax and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aUsageLabel - The usage label printed out by the printHelp() method.
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withCopyrightNote

        default ArgsParser withCopyrightNote​(java.lang.String aCopyrightNote)
        Set the copyright note used by the printHelp() method when writing out the copyright claim and make other adjustments with the result (with regards to the Builder-Pattern).
        Parameters:
        aCopyrightNote - The license note printed out by the printHelp() method.
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withSeparatorChar

        default ArgsParser withSeparatorChar​(char aSeparatorChar)
        Set the character to be used when printing a separator line with the printSeparatorLn() method.
        Parameters:
        aSeparatorChar - The character used by the printSeparatorLn() method when printing out the line of characters..
        Returns:
        This ArgsParser instance with regard to the builder pattern.
      • withTitle

        default ArgsParser withTitle​(java.lang.String aTitle)
        With title.
        Specified by:
        withTitle in interface org.refcodes.mixin.TitleAccessor.TitleBuilder<ArgsParser>
        Parameters:
        aTitle - the title
        Returns:
        the args parser
      • withName

        default ArgsParser withName​(java.lang.String aName)
        With name.
        Specified by:
        withName in interface org.refcodes.mixin.NameAccessor.NameBuilder<ArgsParser>
        Parameters:
        aName - the name
        Returns:
        the args parser
      • withDescription

        default ArgsParser withDescription​(java.lang.String aDescription)
        With description.
        Specified by:
        withDescription in interface org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<ArgsParser>
        Parameters:
        aDescription - the description
        Returns:
        the args parser
      • printBanner

        void printBanner​()
        Prints the banner; the banner most probably is an ASCII art text block which's look depends strongly on the taste of the author implementing this interface.
      • printOptions

        void printOptions​()
        Prints the Options (short- and the long-options), the Flages and the Operand and their description with regards to the console width as specified by the withConsoleWidth(int) method.
      • printSeparatorLn

        void printSeparatorLn​()
        Prints a separator line using the separator character as specified by the withSeparatorChar(char) method; with regards to to the console width as specified by the withConsoleWidth(int) method.
      • printLn

        void printLn​(java.lang.String aLine)
        Prints the given line to standard out with regards to to the console width as specified by the withConsoleWidth(int) method.
        Parameters:
        aLine - The line to be printed.
      • errorLn

        void errorLn​(java.lang.String aLine)
        Prints the given line to standard error with regards to to the console width as specified by the withConsoleWidth(int) method.
        Parameters:
        aLine - The line to be printed.
      • printLn

        void printLn​()
        Prints an empty line / a line break.