public 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()
.
RootConditionAccessor.RootConditionBuilder<B extends RootConditionAccessor.RootConditionBuilder<B>>, RootConditionAccessor.RootConditionMutator, RootConditionAccessor.RootConditionProperty
Constructor and 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 . |
Modifier and Type | Method and Description |
---|---|
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.
|
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).
|
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. |
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.
|
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 |
printHelp()
Prints the help to the standard output specified by the
ArgsParser.withStandardOut(PrintStream) 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
Option s (short- and the long-options), the
Switch es 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.withSeparatorChar(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 |
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 |
setErrorOut(PrintStream aErrorOut)
Set the error out
PrintStream and make other adjustments with the
result (with regards to the Builder-Pattern). |
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 |
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 |
setSeparatorChar(char aSeparatorChar)
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 |
setTitle(String aTitle) |
void |
setUsageLabel(String aUsageLabel)
Set the usage label used by the
ArgsParser.printHelp() method when writing
out the syntax. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
evalArgs, withBannerFont, withBannerFontPalette, withConsoleWidth, withCopyrightNote, withDescription, withErrorOut, withEvalArgs, withEvalArgs, withLicenseNote, withLineBreak, withMaxConsoleWidth, withName, withParseArgs, withSeparatorChar, withStandardOut, withSyntaxNotation, withTitle, withUsageLabel
withParseArgs
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()
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 void setSyntaxNotation(SyntaxNotation aSyntaxNotation)
SyntaxNotation
.setSyntaxNotation
in interface ArgsParser
aSyntaxNotation
- The SyntaxNotation
to set.public void setStandardOut(PrintStream aStandardOut)
PrintStream
and make other adjustments with
the result (with regards to the Builder-Pattern).setStandardOut
in interface ArgsParser
aStandardOut
- The standard out PrintStream
to set.public void setErrorOut(PrintStream aErrorOut)
PrintStream
and make other adjustments with the
result (with regards to the Builder-Pattern).setErrorOut
in interface ArgsParser
aErrorOut
- The error out PrintStream
to set.public 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 ArgsParser
aConsoleWidth
- The width to set or -1 to let the parser
automatically determine the console width.public void setLineBreak(String aLineBreak)
SystemUtility.getLineBreak()
value.setLineBreak
in interface ArgsParser
aLineBreak
- the new line breakpublic void setDescription(String aDescription)
setDescription
in interface org.refcodes.mixin.DescriptionAccessor.DescriptionMutator
public void setName(String aName)
setName
in interface org.refcodes.mixin.NameAccessor.NameMutator
public void setLicenseNote(String aLicenseNote)
ArgsParser.printHelp()
method when writing
out the licensing conditions.setLicenseNote
in interface ArgsParser
aLicenseNote
- The license note printed out by the
ArgsParser.printHelp()
method.public void setUsageLabel(String aUsageLabel)
ArgsParser.printHelp()
method when writing
out the syntax.setUsageLabel
in interface ArgsParser
aUsageLabel
- The usage label printed out by the
ArgsParser.printHelp()
method.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 ArgsParser
aCopyrightNote
- The license note printed out by the
ArgsParser.printHelp()
method.public void setSeparatorChar(char aSeparatorChar)
ArgsParser.printSeparatorLn()
method.setSeparatorChar
in interface ArgsParser
aSeparatorChar
- The character used by the
ArgsParser.printSeparatorLn()
method when printing out the line of
characters..public void setBannerFont(org.refcodes.textual.Font aBannerFont)
setBannerFont
in interface ArgsParser
aBannerFont
- the new banner fontpublic void setBannerFontPalette(char[] aColorPalette)
setBannerFontPalette
in interface ArgsParser
aColorPalette
- the new banner font palettepublic void setTitle(String aTitle)
setTitle
in interface org.refcodes.mixin.TitleAccessor.TitleMutator
public void setMaxConsoleWidth(int aMaxConsoleWidth)
setMaxConsoleWidth
in interface ArgsParser
aMaxConsoleWidth
- the new max console widthpublic void printLicenseNote()
ArgsParser.withLicenseNote(String)
method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int)
method.printLicenseNote
in interface ArgsParser
public void printCopyrightNote()
ArgsParser.withCopyrightNote(String)
method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int)
method.printCopyrightNote
in interface ArgsParser
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[])
method; as
ignoring superfluous command line arguments will cause unexpected
behavior from the point of view of the invoker.evalArgs
in interface ArgsParser
aArgs
- 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 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 ArgsParser
public void printHelp()
ArgsParser.withStandardOut(PrintStream)
method. This method can make use of
the more atomic methods ArgsParser.printBanner()
, ArgsParser.printUsage()
,
ArgsParser.printDescription()
, ArgsParser.printOptions()
or
ArgsParser.printSeparatorLn()
to print a help text which's look depends
strongly on the taste of the author implementing this interface. In case
you dislike the implementing author's taste, feel free to overwrite this
method and compose your own help text from the building blocks such as
ArgsParser.printBanner()
, ArgsParser.printUsage()
,
ArgsParser.printDescription()
, ArgsParser.printOptions()
or
ArgsParser.printSeparatorLn()
printHelp
in interface ArgsParser
public void printDescription()
ArgsParser.withDescription(String)
method with regards to the console width as specified by the
ArgsParser.withConsoleWidth(int)
method.printDescription
in interface ArgsParser
public void printLn(String aLine)
ArgsParser.withConsoleWidth(int)
method.printLn
in interface ArgsParser
aLine
- The line to be printed.public void errorLn(String aLine)
ArgsParser.withConsoleWidth(int)
method.errorLn
in interface ArgsParser
aLine
- The line to be printed.public void printLn()
printLn
in interface ArgsParser
public void printSeparatorLn()
ArgsParser.withSeparatorChar(char)
method; with regards to to the console
width as specified by the ArgsParser.withConsoleWidth(int)
method.printSeparatorLn
in interface ArgsParser
public void printBanner()
printBanner
in interface ArgsParser
public void printOptions()
Option
s (short- and the long-options), the
Switch
es and the Operand
and their description with
regards to the console width as specified by the
ArgsParser.withConsoleWidth(int)
method.printOptions
in interface ArgsParser
public Condition getRootCondition()
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.getRootCondition
in interface ArgsParser
getRootCondition
in interface RootConditionAccessor
Condition
in which's syntax this parser is
based.public void reset()
reset
in interface org.refcodes.component.Resetable
protected char getDelimiter()
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.Switch
and
StringOperandImpl
instances.Copyright © 2018. All rights reserved.