ArgsParser, ArgsParserMixin<ArgsParser>, RootConditionAccessor, org.refcodes.component.Resetable, org.refcodes.mixin.DescriptionAccessor, org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<ArgsParser>, org.refcodes.mixin.DescriptionAccessor.DescriptionMutator, org.refcodes.mixin.DescriptionAccessor.DescriptionProperty, org.refcodes.mixin.EscapeCodesStatusAccessor, org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusBuilder<ArgsParser>, org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusMutator, org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusProperty, org.refcodes.mixin.NameAccessor, org.refcodes.mixin.NameAccessor.NameBuilder<ArgsParser>, org.refcodes.mixin.NameAccessor.NameMutator, org.refcodes.mixin.NameAccessor.NameProperty, org.refcodes.mixin.ResetEscapeCodeAccessor, org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeBuilder<ArgsParser>, org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeMutator, org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeProperty, org.refcodes.mixin.TitleAccessor, org.refcodes.mixin.TitleAccessor.TitleBuilder<ArgsParser>, org.refcodes.mixin.TitleAccessor.TitleMutator, org.refcodes.mixin.TitleAccessor.TitleProperty, org.refcodes.textual.TextBoxGridAccessor, org.refcodes.textual.TextBoxGridAccessor.TextBoxGridBuilder<ArgsParser>, org.refcodes.textual.TextBoxGridAccessor.TextBoxGridMutator, org.refcodes.textual.TextBoxGridAccessor.TextBoxGridPropertypublic class ArgsParserImpl extends Object implements ArgsParser
ArgsParser interface. The
constructor only provides means to set the required attributes as the
attributes to be adjusted optionally are already sufficiently pre-configured.
For adjusting them, a flavor of the Builder-Pattern is provided with which
you can easily chain the configuration of this instance; as them methods
return the instance of this class being configured. This helps to prevent the
telescoping constructor anti-pattern.
The SyntaxNotation is pre-set with the
SyntaxNotation.REFCODES notation.
The console width id pre-configured with the console's width as determined by
the SystemUtility.getTerminalWidth().
The standard out PrintStream is pre-configured with the
System.out PrintStream.
The newline characters to be used for line breaks is "\r\n" on Windows
machines and "\"n" on all other machines as of the
SystemUtility.getLineBreak().
org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<B extends org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<B>>, org.refcodes.mixin.DescriptionAccessor.DescriptionMutator, org.refcodes.mixin.DescriptionAccessor.DescriptionPropertyorg.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusBuilder<B extends org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusBuilder<B>>, org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusMutator, org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusPropertyorg.refcodes.mixin.NameAccessor.NameBuilder<B extends org.refcodes.mixin.NameAccessor.NameBuilder<B>>, org.refcodes.mixin.NameAccessor.NameMutator, org.refcodes.mixin.NameAccessor.NamePropertyorg.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeBuilder<B extends org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeBuilder<B>>, org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeMutator, org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodePropertyRootConditionAccessor.RootConditionBuilder<B extends RootConditionAccessor.RootConditionBuilder<B>>, RootConditionAccessor.RootConditionMutator, RootConditionAccessor.RootConditionPropertyorg.refcodes.textual.TextBoxGridAccessor.TextBoxGridBuilder<B extends org.refcodes.textual.TextBoxGridAccessor.TextBoxGridBuilder<?>>, org.refcodes.textual.TextBoxGridAccessor.TextBoxGridMutator, org.refcodes.textual.TextBoxGridAccessor.TextBoxGridProperty| Modifier and Type | Field | Description |
|---|---|---|
protected PrintStream |
_errStream |
|
protected PrintStream |
_stdStream |
| Constructor | Description |
|---|---|
ArgsParserImpl() |
Constructs the
ArgsParser instance without any restrictions to
the parsed arguments. |
ArgsParserImpl(Condition aRootCondition) |
Constructs the
ArgsParser instance with the given root
Condition and the default SyntaxNotation.REFCODES. |
ArgsParserImpl(Option<?> aRootOption) |
Constructs the
ArgsParser instance with the given root
Option and the default SyntaxNotation.REFCODES. |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addExampleUsage(String aDescription,
Operand<?>... aOperands) |
Adds a usage example by providing a description of the example and the
command line arguments required by the example.
|
void |
errorLn(String aLine) |
Prints the given line to standard error with regards to to the console
width as specified by the
ArgsParser.withConsoleWidth(int) method. |
List<? extends Operand<?>> |
evalArgs(String[] aArgs) |
Evaluates the provided command line arguments and determines the
according values by evaluating the root
Condition. |
protected static List<? extends Operand<?>> |
fromArgs(String[] aArgs,
char aDelimiter) |
Heuristically loads the arguments without any syntax required, e.g.
|
String |
getBannerBorderEscapeCode() |
Retrieves the banner's border Escape-Code from the banner border
Escape-Code property.
|
String |
getBannerEscapeCode() |
Retrieves the banner's content Escape-Code from the banner Escape-Code
property.
|
String |
getCopyrightNote() |
Retrieves the copyright.
|
protected char |
getDelimiter() |
Returns the delimiter to be used by colliding command line args when
creating non colliding arg's aliases (keys for key/value-pairs).
|
String |
getDescription() |
Retrieves the description.
|
String |
getDescriptionEscapeCode() |
Retrieves the parameter's description Escape-Code from the parameter's
description Escape-Code property.
|
List<ExampleUsage> |
getExampleUsages() |
Retrieves the
ExampleUsage instances as addeed using
ArgsParser.addExampleUsage(String, Operand...). |
String |
getLicenseNote() |
Retrieves the license.
|
String |
getLineSeparatorEscapeCode() |
Retrieves the line separator Escape-Code from the line separator
Escape-Code property.
|
String |
getName() |
|
String |
getParameterEscapeCode() |
Retrieves the parameter Escape-Code from the parameter Escape-Code
property.
|
String |
getResetEscapeCode() |
|
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. |
char |
getSeparatorLnChar() |
Gets the character to be used when printing a separator line with the
ArgsParser.printSeparatorLn() method. |
org.refcodes.textual.TextBoxGrid |
getTextBoxGrid() |
|
String |
getTitle() |
|
boolean |
isEscapeCodesEnabled() |
|
void |
printBanner() |
Prints the banner; the banner most probably is an ASCII_HEADER_ASCII_BODY
art text block which's look depends strongly on the taste of the author
implementing this interface.
|
void |
printCopyrightNote() |
Prints the copyright note as specified by the
ArgsParser.withCopyrightNote(String) method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int) method. |
void |
printDescription() |
Prints the description as set by the
ArgsParser.withDescription(String)
method with regards to the console width as specified by the
ArgsParser.withConsoleWidth(int) method. |
void |
printExampleUsages() |
Prints example usages as as added by the
ArgsParser.addExampleUsage(String, Operand...) method with regards to the
console width as specified by the ArgsParser.withConsoleWidth(int) method. |
void |
printLicenseNote() |
Prints the license note as specified by the
ArgsParser.withLicenseNote(String) method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int) method. |
void |
printLn() |
Prints an empty line / a line break.
|
void |
printLn(String aLine) |
Prints the given line to standard out with regards to to the console
width as specified by the
ArgsParser.withConsoleWidth(int) method. |
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 ArgsParser.withConsoleWidth(int)
method. |
void |
printSeparatorLn() |
Prints a separator line using the separator character as specified by the
ArgsParser.withSeparatorLnChar(char) method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int) method. |
void |
printUsage() |
Prints the syntax as retrieved by the root
Condition with regards
to the SyntaxNotation set by the
ArgsParser.withSyntaxNotation(SyntaxNotation) method; making use of the
usage label as passed by the ArgsParser.withUsageLabel(String) method. |
void |
reset() |
|
void |
setBannerBorderEscapeCode(String aBannerBorderEscCode) |
Sets the banner's border Escape-Code for the banner border Escape-Code
property.
|
void |
setBannerEscapeCode(String aBannerEscCode) |
Sets the banner's content Escape-Code for the banner Escape-Code
property.
|
void |
setBannerFont(org.refcodes.textual.Font aBannerFont) |
Sets the banner font.
|
void |
setBannerFontPalette(char[] aColorPalette) |
Sets the banner font palette.
|
void |
setConsoleWidth(int aConsoleWidth) |
Set the console with.
|
void |
setCopyrightNote(String aCopyrightNote) |
Set the copyright note used by the
ArgsParser.printHelp() method when
writing out the copyright claim and make other adjustments with the
result (with regards to the Builder-Pattern). |
void |
setDescription(String aDescription) |
|
void |
setDescriptionEscapeCode(String aDescriptionEscCode) |
Sets the description Escape-Code for the description Escape-Code
property.
|
void |
setErrorOut(PrintStream aErrorOut) |
Set the error out
PrintStream and make other adjustments with the
result (with regards to the Builder-Pattern). |
void |
setEscapeCodesEnabled(boolean isEscCodeEnabled) |
|
void |
setLicenseNote(String aLicenseNote) |
Set the license note used by the
ArgsParser.printHelp() method when writing
out the licensing conditions. |
void |
setLineBreak(String aLineBreak) |
Set the console's line break.
|
void |
setLineSeparatorEscapeCode(String aLineSeparatorEscCode) |
Sets the line separator Escape-Code for the line separator Escape-Code
property.
|
void |
setMaxConsoleWidth(int aMaxConsoleWidth) |
Set the maximum console width to use in case the console width is greater
than the maximum you want.
|
void |
setName(String aName) |
|
void |
setParameterEscapeCode(String aParamEscCode) |
Sets the parameter Escape-Code for the parameter Escape-Code property.
|
void |
setResetEscapeCode(String aResetEscCode) |
|
void |
setSeparatorLnChar(char aSeparatorLnChar) |
Set the character to be used when printing a separator line with the
ArgsParser.printSeparatorLn() method. |
void |
setStandardOut(PrintStream aStandardOut) |
Set the standard out
PrintStream and make other adjustments with
the result (with regards to the Builder-Pattern). |
void |
setSyntaxNotation(SyntaxNotation aSyntaxNotation) |
Set the
SyntaxNotation. |
void |
setTextBoxGrid(org.refcodes.textual.TextBoxGrid aTextBoxGrid) |
|
void |
setTitle(String aTitle) |
|
void |
setUsageLabel(String aUsageLabel) |
Set the usage label used by the
ArgsParser.printHelp() method when writing
out the syntax. |
evalArgs, printBody, printHelp, withBannerBorderEscapeCode, withBannerEscapeCode, withBannerFont, withBannerFontPalette, withConsoleWidth, withCopyrightNote, withDescription, withDescriptionEscapeCode, withErrorOut, withEscapeCodesEnabled, withEvalArgs, withEvalArgs, withExampleUsage, withLicenseNote, withLineBreak, withLineSeparatorEscapeCode, withMaxConsoleWidth, withName, withParameterEscapeCode, withResetEscapeCode, withSeparatorLnChar, withStandardOut, withSyntaxNotation, withTextBoxGrid, withTitle, withUsageLabelletDescriptionletEscapeCodesEnabledclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitletResetEscapeCodeprotected PrintStream _stdStream
protected PrintStream _errStream
public ArgsParserImpl()
ArgsParser instance without any restrictions to
the parsed arguments. The constructor only provides means to set the
required attributes as the attributes to be adjusted optionally are
already sufficiently pre-configured. For adjusting them, a flavor of the
Builder-Pattern is provided with which you can easily chain the
configuration of this instance; as them methods return the instance of
this class being configured.public ArgsParserImpl(Condition aRootCondition)
ArgsParser instance with the given root
Condition and the default SyntaxNotation.REFCODES. The
constructor only provides means to set the required attributes as the
attributes to be adjusted optionally are already sufficiently
pre-configured. For adjusting them, a flavor of the Builder-Pattern is
provided with which you can easily chain the configuration of this
instance; as them methods return the instance of this class being
configured.aRootCondition - The root condition being the node from which
parsing the command line arguments starts.public ArgsParserImpl(Option<?> aRootOption)
ArgsParser instance with the given root
Option and the default SyntaxNotation.REFCODES. The
constructor only provides means to set the required attributes as the
attributes to be adjusted optionally are already sufficiently
pre-configured. For adjusting them, a flavor of the Builder-Pattern is
provided with which you can easily chain the configuration of this
instance; as them methods return the instance of this class being
configured.aRootOption - The root option being the node from which parsing the
command line arguments starts.public String getLineSeparatorEscapeCode()
getLineSeparatorEscapeCode in interface ArgsParserpublic void setLineSeparatorEscapeCode(String aLineSeparatorEscCode)
setLineSeparatorEscapeCode in interface ArgsParseraLineSeparatorEscCode - The line separator Escape-Code to be stored
by the line separator Escape-Code property.public String getBannerEscapeCode()
getBannerEscapeCode in interface ArgsParserpublic String getBannerBorderEscapeCode()
getBannerBorderEscapeCode in interface ArgsParserpublic void setBannerEscapeCode(String aBannerEscCode)
setBannerEscapeCode in interface ArgsParseraBannerEscCode - The banner Escape-Code to be stored by the banner
Escape-Code property.public void setBannerBorderEscapeCode(String aBannerBorderEscCode)
setBannerBorderEscapeCode in interface ArgsParseraBannerBorderEscCode - The banner border Escape-Code to be stored by
the banner border Escape-Code property.public String getParameterEscapeCode()
getParameterEscapeCode in interface ArgsParserpublic void setParameterEscapeCode(String aParamEscCode)
setParameterEscapeCode in interface ArgsParseraParamEscCode - The parameter Escape-Code to be stored by the
parameter Escape-Code property.public void errorLn(String aLine)
ArgsParser.withConsoleWidth(int) method.errorLn in interface ArgsParseraLine - The line to be printed.public List<? extends Operand<?>> evalArgs(String[] aArgs) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException
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 ArgsParser.evalArgs(String[]) method instead of a
Condition's Syntaxable.parseArgs(String[], String[])
method; as ignoring superfluous command line arguments will cause
unexpected behavior from the point of view of the invoker.evalArgs in interface ArgsParseraArgs - The command line arguments to be evaluated.Operand interfaces or its sub-types.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 typepublic String getCopyrightNote()
getCopyrightNote in interface ArgsParserprotected char getDelimiter()
public String getDescription()
getDescription in interface ArgsParsergetDescription in interface org.refcodes.mixin.DescriptionAccessorpublic String getLicenseNote()
getLicenseNote in interface ArgsParserpublic String getName()
getName in interface org.refcodes.mixin.NameAccessorpublic Condition getRootCondition()
Syntaxable
hierarchy to be traversed when determining the syntax for command line
arguments or when evaluating the command line arguments. Retrieves the root condition from the root condition property.getRootCondition in interface ArgsParsergetRootCondition in interface RootConditionAccessorCondition in which's syntax this parser is
based.public String getResetEscapeCode()
getResetEscapeCode in interface org.refcodes.mixin.ResetEscapeCodeAccessorpublic void setResetEscapeCode(String aResetEscCode)
setResetEscapeCode in interface org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeMutatorpublic String getTitle()
getTitle in interface org.refcodes.mixin.TitleAccessorpublic void printBanner()
printBanner in interface ArgsParserpublic void printCopyrightNote()
ArgsParser.withCopyrightNote(String) method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int) method.printCopyrightNote in interface ArgsParserpublic void printDescription()
ArgsParser.withDescription(String)
method with regards to the console width as specified by the
ArgsParser.withConsoleWidth(int) method.printDescription in interface ArgsParserpublic void printLicenseNote()
ArgsParser.withLicenseNote(String) method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int) method.printLicenseNote in interface ArgsParserpublic void printLn()
printLn in interface ArgsParserpublic void printLn(String aLine)
ArgsParser.withConsoleWidth(int) method.printLn in interface ArgsParseraLine - The line to be printed.public void printOptions()
Options (short- and the long-options), the
Flages and the Operand and their description with regards
to the console width as specified by the ArgsParser.withConsoleWidth(int)
method.printOptions in interface ArgsParserpublic void printExampleUsages()
ArgsParser.addExampleUsage(String, Operand...) method with regards to the
console width as specified by the ArgsParser.withConsoleWidth(int) method.printExampleUsages in interface ArgsParserpublic void printSeparatorLn()
ArgsParser.withSeparatorLnChar(char) method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int) method.printSeparatorLn in interface ArgsParserpublic void printUsage()
Condition with regards
to the SyntaxNotation set by the
ArgsParser.withSyntaxNotation(SyntaxNotation) method; making use of the
usage label as passed by the ArgsParser.withUsageLabel(String) method.printUsage in interface ArgsParserpublic void reset()
reset in interface org.refcodes.component.Resetablepublic void setBannerFont(org.refcodes.textual.Font aBannerFont)
setBannerFont in interface ArgsParseraBannerFont - the new banner fontpublic void setBannerFontPalette(char[] aColorPalette)
setBannerFontPalette in interface ArgsParseraColorPalette - the new banner font palettepublic void setConsoleWidth(int aConsoleWidth)
SystemUtility.getTerminalWidth() value, i.e. the console
width is set automatically to be the width of your terminal.setConsoleWidth in interface ArgsParseraConsoleWidth - The width to set or -1 to let the parser
automatically determine the console width.public void setCopyrightNote(String aCopyrightNote)
ArgsParser.printHelp() method when
writing out the copyright claim and make other adjustments with the
result (with regards to the Builder-Pattern).setCopyrightNote in interface ArgsParseraCopyrightNote - The license note printed out by the
ArgsParser.printHelp() method.public void setDescription(String aDescription)
setDescription in interface org.refcodes.mixin.DescriptionAccessor.DescriptionMutatorpublic void setErrorOut(PrintStream aErrorOut)
PrintStream and make other adjustments with the
result (with regards to the Builder-Pattern).setErrorOut in interface ArgsParseraErrorOut - The error out PrintStream to set.public boolean isEscapeCodesEnabled()
isEscapeCodesEnabled in interface org.refcodes.mixin.EscapeCodesStatusAccessorpublic void setEscapeCodesEnabled(boolean isEscCodeEnabled)
setEscapeCodesEnabled in interface org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusMutatorpublic String getDescriptionEscapeCode()
getDescriptionEscapeCode in interface ArgsParserpublic void setDescriptionEscapeCode(String aDescriptionEscCode)
setDescriptionEscapeCode in interface ArgsParseraDescriptionEscCode - The description Escape-Code to be stored by
the description Escape-Code property.public void setLicenseNote(String aLicenseNote)
ArgsParser.printHelp() method when writing
out the licensing conditions.setLicenseNote in interface ArgsParseraLicenseNote - The license note printed out by the
ArgsParser.printHelp() method.public void setLineBreak(String aLineBreak)
SystemUtility.getLineBreak() value.setLineBreak in interface ArgsParseraLineBreak - the new line breakpublic void setMaxConsoleWidth(int aMaxConsoleWidth)
setMaxConsoleWidth in interface ArgsParseraMaxConsoleWidth - the new max console widthpublic void setName(String aName)
setName in interface org.refcodes.mixin.NameAccessor.NameMutatorpublic void setSeparatorLnChar(char aSeparatorLnChar)
ArgsParser.printSeparatorLn() method.setSeparatorLnChar in interface ArgsParseraSeparatorLnChar - The character used by the
ArgsParser.printSeparatorLn() method when printing out the line of
characters..public char getSeparatorLnChar()
ArgsParser.printSeparatorLn() method.getSeparatorLnChar in interface ArgsParserArgsParser.printSeparatorLn() method when printing out the line of
characters..public void setStandardOut(PrintStream aStandardOut)
PrintStream and make other adjustments with
the result (with regards to the Builder-Pattern).setStandardOut in interface ArgsParseraStandardOut - The standard out PrintStream to set.public void setSyntaxNotation(SyntaxNotation aSyntaxNotation)
SyntaxNotation.setSyntaxNotation in interface ArgsParseraSyntaxNotation - The SyntaxNotation to set.public void setTitle(String aTitle)
setTitle in interface org.refcodes.mixin.TitleAccessor.TitleMutatorpublic void setUsageLabel(String aUsageLabel)
ArgsParser.printHelp() method when writing
out the syntax.setUsageLabel in interface ArgsParseraUsageLabel - The usage label printed out by the
ArgsParser.printHelp() method.public org.refcodes.textual.TextBoxGrid getTextBoxGrid()
getTextBoxGrid in interface org.refcodes.textual.TextBoxGridAccessorpublic void setTextBoxGrid(org.refcodes.textual.TextBoxGrid aTextBoxGrid)
setTextBoxGrid in interface org.refcodes.textual.TextBoxGridAccessor.TextBoxGridMutatorpublic List<ExampleUsage> getExampleUsages()
ExampleUsage instances as addeed using
ArgsParser.addExampleUsage(String, Operand...).getExampleUsages in interface ArgsParserExampleUsage elements.public void addExampleUsage(String aDescription, Operand<?>... aOperands)
addExampleUsage in interface ArgsParseraDescription - The description of the example.aOperands - The command line arguments used by the example.protected static List<? extends Operand<?>> fromArgs(String[] aArgs, char aDelimiter)
Condition to be set.aArgs - The arguments to be loaded.aDelimiter - The delimiter to resolve name clashes.Flag and
StringOperand instances.Copyright © 2021. All rights reserved.