Version 1.0.0 - First stable release
Documentation now available!
Check out the complete documentation at https://darvil82.github.io/lanat-docs
Features
-
Argument types
- Add
ActionArgumentType
. This is the oldBooleanArgumentType
. BooleanArgumentType
can now receive values as well. Those beingtrue
,false
,yes
,no
, etc.TupleArgumentType
is no longer abstract and does not take a default value in its constructor now. Instead takes another argument type instance. The tuple argument type can now work with any argument type passed to it.- Change
forEachArgValue()
togetArgValuesStream()
. - Add
getRequiredUsageCount()
toParseable
. - Add default implementation to
getRequiredUsageCount
andgetRequiredArgValueCount
inParseable
. TryParseArgumentType
will now try to infer the type first if possible.- Make
Parseable
a functional interface. - Add
SimpleArgumentType
. Allows to create argument types with a builder pattern. Implements the aforementionedBuilder
. - Add
OptListArgumentType
. Similar toEnumArgumentType
, but accepts a list of all possible strings the user can introduce. - Add
SingleValueListArgumentType
abstract class.EnumArgumentType
andOptListArgumentType
both inherit this. - Add constructor to
ArgumentType
to pass aParseable
to check restrictions on. - Add
unregisterSubType()
toArgumentType
. - Add
unregister
toArgumentTypeInfer
. - Add
ArgumentTypeError
. - Argument types now throw
ArgumentTypeError
instead ofCustomErrorImpl
.
- Add
-
AfterParseOptions
- Actions are now supplied by using the
withActions()
method, which accepts a callback defining the actions chain. - Actions are now run when a terminating method is called. These are either
getResult()
orinto()
. This ensures other callbacks defined are invoked at the correct time. - The default actions chain is now
DEFAULT_ACTIONS
.public static final Consumer<@NotNull AfterParseActions> DEFAULT_ACTIONS = a -> a .printHelpIfNoInput() .exitIfNoInput() .printErrors() .exitIfErrors();
- Add
hasReceivedInput()
to check if the program received any input at all.
- Actions are now supplied by using the
-
Arguments
- Add
visible
property. This allows to hide this argument from the help message. Use thesetVisible
method. This property has been added toArgumentBuilder
and theArgument.Define
annotation as well. - Remove
Argument.createOfBoolType()
in favor of newArgument.createOfActionType()
. - Arguments are now represented in help with a single prefix.
- Positional arguments will now be the first to appear in the help synopsis representation.
- Improve how arguments appear in help descriptions. Multiple names are now shown in a less confusing manner.
- Add
isOrphan()
. Returnstrue
if this argument doesn't belong to any command or group. - Add
removePrefix()
static method. - When specifying the argument type upon argument creation, a
Builder<ArgumentType>
may also be specified instead.
- Add
-
Commands
- Add
int
parameter toaddHelpArgument()
andaddVersionArgument()
to specify the exit code upon quitting. - Add
onUsed
callback. Can be set withsetOnUsedCallback()
. This callback is functionally equivalent toCommandTemplate#onUsed
. Command#getParseResult
will return cached results if called multiple times.- Templates
- Greatly improved error messages when creating arguments from command template fields.
- Groups can now be defined in command templates by setting the
group
value in theArgument.Define
annotation. Multiple argument fields defined with the samegroup
value will be added to a group with that name. - Add
argWithType
helper method toCommandBuildHelper
to remove the need to specify type parameters while setting the type. - Add
CommandTemplate.Default.WithVerbose
, which includes averbose
counter argument. - Add error to make it clear the user must manually provide the argument type when using
Optional
in the command template field. onUsed
now received theParseResult
instance as a parameter.
- Add
-
Misc
- Now supports the NO-COLOR environment variable.
com.darvil:utils
andcom.darvil:terminal-text-formatter
are now both API dependencies, thus the user will no longer have to manually install them.- Add
CLInput#fromFile
andCLInput#fromStandardInput
. - Add
ArgumentParser#parseFromInto
overload that takesString[]
for ease of use. - Argument group help descriptions now always show arguments even if these don't have any description set. Applies to nested groups.
- Greatly improve error messages when there is a failure when inferring types.
- Parsing a help description tag like
<tag=>
will now be considered invalid syntax. - Add
Builder<T>
interface. Custom builders may be made implementing this interface.ArgumentBuilder
now implementsBuilder
.
ArgumentAdder#addArgument
now accepts a genericBuilder
instance too.- Improve
toString
representation of arguments and commands and groups. - Add
setNames
method toMultipleNamesAndDescription
. Implementors now only implement this method.addNames
has a default implementation now. - Add
unregister
method toTag
. - Negative margin and indent values are no longer silently capped to 0 when negative. Now throws.
- Improve
ColorTag
syntax. Now accepts true color values with thecolor_name|#rrggbb|r,g,b
syntax. - Add
DefaultValueTag
for arguments. - Errors may now choose to remove other errors by overriding the
shouldRemoveOther()
method inError
.- A
RequiredArgumentNotUsedError
will no longer appear if anIncorrectValueNumberError
is present for the same argument. - An
UnmatchedTokenError
will no longer appear if aSimilarArgumentError
is present for the same token index.
- A
- Add
representationColor
toArgumentBuilder
. - When mentioning elements in a a command (such as arguments), errors will now use their actual help representation instead of just the name.
- Add
SimpleError
. - Commands may now contain
Error<?>
instead of being restricted toCustomError
(now removed).
Fixes
- Fix help message not appearing if no input was provided. (Default actions)
- Fix index out of bounds exception being thrown when the last character in the input is a backslash.
- Optimized initialization of many internal lists that most of the time aren't filled that much.
- Fix description of commands always showing up in the help message.
- Fix crash when attempting to add arguments to a group that has already been added to a command.
- Fix argument group descriptions showing up if no arguments inside it have descriptions.
- Fix crash in some cases when registering a group.
- Fix default value of arguments not properly being used in some cases.
- Fix
KeyValuesArgumentType
adding null values when keys fail to parse. ArgumentTypeInfer
can no longer be instantiated.- Fix incorrect report for the
SimilarArgument
parse error. - Fix an error when attempting to close a string inside a tuple.
- Optimize
Argument#checkMatch
to not perform many useless string concatenations. - Fix
Tag#register
method allowing to replace previous entries. - Fix
DescriptionParser
not properly parsing backslashes if no tags are present. - Fix
DescriptionParser
throwingIllegalArgumentException
instead ofMalformedTagException
in a case. - Fix
DescriptionParser
not throwing aMalformedTagException
if a tag is blank. - Fix argument descriptions showing up as "null" if none had descriptions set.
- Tag name and value not being trimmed correctly.
- Fix being possible to use arguments when a unique argument was used. Added new parse error for this.
- Fix
LinkTag
giving incorrect representations for groups. - Fix terminal sequences not resetting properly on descriptions.
- Fix
HelpFormatter#setIndentSize
,getIndentSize
and all its usages not being static. - Fix
CommandTemplate#afterInit
only accepting equal types, but not assignable toCommand
. (Can now acceptArgumentParser
) - Fix program details layout item missing an indentation in the help message.
ArgumentTypeInfer
allowing to set infer forOptional
.- Fix help message printing extra line feed.
CLInput#fromSystemProperty
not working properly when no input is passed in.- Argument types allowing to throw errors before parsing started, potentially crashing.
Refactors
- Move
AfterParseOptions
to its own class. - Rename
Argument#argType
toArgument#type
. Applies toArgumentBuilder
andArgument.Define
as well. - Remove
Argument.create()
overloads involvingchar
. - Commands no longer have the ability to define the tuple char to use. This is now globally defined in
TupleChar#current
. - Move
CallbacksInvocationOption
intoCommand
. - Change all
\n
usages toSystem#lineSeparator()
to improve compatibility. PrefixChar
is now an enum. It is no longer allowed to use any character for a prefix. TheArgument.Define
annotation now uses this enum for the prefixChar value.- The default prefix may now be set with
PrefixChar.setDefaultPrefix()
. - Remove duplicated code in
ArgumentGroupRepr
. - Reorganized many files and code.
- Argument groups are now added differently. The group hierarchy is linked right before parsing now.
- Remove
MultipleNumbersArgumentType
andMultipleStringsArgumentType
. No longer needed with the newTupleArgumentType
. - Rename "license" to "program details" (help message).
- Rename "args" to "values" in argument types.
- Remove unnecessary anonymous subclassing in some places.
- Remove
ArgumentType#setValue()
. - Rename
ErrorsContainer
,ErrorsCollector
andErrorsContainerImpl
to singularError
. (eg, ErrorContainer) - Rename
CommandTemplate#onValuesReceived
toCommandTemplate#onUsed
. - Changed naming convention of setter methods in
ArgumentBuilder
. - Rename
DescriptionFormatter
toDescriptionParser
. lanat.parsing.errors.handlers
is no longer exported.ArgumentBuilder
boolean setters now accept values and other setters acceptnull
values.- Rename
LayoutItem
formatting methods. - Replace all
UtlMisc#nullOrElseGet()
usages withOptional
s. (RemovedUtlMisc#nullOrElseGet()
) - Replace all
UtlString#allCharsMatch()
withString#chars()
. HelpFormatter#indentSize
is no longer an instance property.LayoutItem#indentCount
,HelpFormatter#lineWrapMax
andHelpFormatter#indentSize
are now stored as anint
.- Remove all single/double character color value options in
ColorTag
. Now the whole name must be provided to avoid confusion. (except gray/grey) - Remove single character value options in
FormatTag
fordim
,blink
,reverse
andhidden
. - Supplying no values in
FormatTag
andColorTag
will now throw aMalformedTagException
. - Refactor some code to use
Optional
instead of regularnull
checks. - Remove unnecessary
Tokenizer#inputChars
. ArgumentTypeInfer#register
only accepts a single class now. Same withunregister
. AddedArgumentTypeInfer#registerWithPrimitive
andArgumentTypeInfer#unregisterWithPrimitive
.- Rename
getRequiredUsageCount
togetUsageCountBounds
andgetRequiredArgValueCount
togetValueCountBounds
inArgumentType
. - Rename
PrefixChar
to justPrefix
. - Slight method refactors in
HelpFormatter
andLayoutItem
. - Remove
ParseResult#get(String)
. The only method is now theString...
overload. - Move
addHelp
andaddVersion
methods inCommand
toCommandTemplate.Default
.
Misc
- Bump
utils
andterminal-text-formatter
to latest. - Update
README.md
to reflect all these changes. - Remove
ExampleTest
. - Fix logo.
- Fix plenty of typos in javadocs.
- Add more tests.
- Properly set nullability annotations.