Class Argument.ArgumentBuilder<T>
java.lang.Object
com.clumd.projects.java_common_utils.arg_parser.Argument.ArgumentBuilder<T>
- Type Parameters:
T- The param type for the builder matching that of the base Argument class.
Overridden Builder for part of the Lombok process. This is used to alter the basic setter functionality of the
chained methods in the builder, dependent on the field being overridden.
-
Method Summary
Modifier and TypeMethodDescriptionargumentResult(T argumentResult) If this argument needs a value, then this should be the fully validated and parsed output of that value.build()<E extends Exception>
Argument.ArgumentBuilder<T>conversionFunction(FunctionPotentialException<String, T, E> functionWhichMayThrowException) This constructor is used to override the conversion function in order to wrap the call to theFunction.apply(Object)such that the implementing user can use checked exceptions if they want, without it causing compile time issues.defaultValue(T toValue) Used to set the default value, and also mark that the default value has been set.defaultValueSet(boolean defaultValueSet) Used to track if a default value has been set for this argument to be used if no CLI value is found.description(String description) Used to describe the purpose of this Argument and how it should be used.hasValue(boolean toValue) This is used to set the hasValue of this argument, it is only required as an override to the default constructor to allow the conversionFunction to trigger a change of state when a conversionFunction is provided.isMandatory(boolean isMandatory) Used to indicate if this argument is mandatory and MUST be provided for the utilising code to function.longOptions(Set<String> longOptions) Used to contain all the word alias' to indicate this optionmustBeUsedWith(Set<String> mustBeUsedWith) Used to denote other CLI Arguments (by reference to theirArgument.uniqueId) which MUST be present if, and only if, this Argument is found on the CLI.mustNotBeUsedWith(Set<String> mustNotBeUsedWith) Used to denote other CLI Arguments (by reference to theirArgument.uniqueId) which MUST NOT be used in conjunction with this one if, and only if, this Argument is found on the CLI.shortOptions(Set<Character> shortOptions) Used to contain all the single character alias' to indicate this optionshouldShortCircuit(boolean shouldShortCircuit) Used to tell a parser that if this argument is detected on the CLI at all, it should ALWAYS be returnable to the caller with all present short circuit args.toString()This is used to set the uniqueId of this argument, it is only required as an override to the default constructor to have the value available to the exception strings in theFunctionPotentialExceptionmethods below<E extends Exception>
Argument.ArgumentBuilder<T>validationFunction(FunctionPotentialException<T, Boolean, E> functionWhichMayThrowException) This constructor is used to override the value validation function in order to wrap the call to theFunction.apply(Object)such that the implementing user can use checked exceptions if they want, without it causing compile time issues.valueIsOptional(boolean valueIsOptional) Used to indicate if the value to this argument can be optional, defaults to false.
-
Method Details
-
uniqueId
This is used to set the uniqueId of this argument, it is only required as an override to the default constructor to have the value available to the exception strings in theFunctionPotentialExceptionmethods below- Parameters:
toValue- Used to index the options, must be unique and supplied by the user.- Returns:
- This continued builder instance.
-
hasValue
This is used to set the hasValue of this argument, it is only required as an override to the default constructor to allow the conversionFunction to trigger a change of state when a conversionFunction is provided.- Parameters:
toValue- Used to determine whether this Argument can be followed with a value.- Returns:
- This continued builder instance.
-
defaultValue
Used to set the default value, and also mark that the default value has been set. This can be used to notify a local Arg Parser that a local value exists, in case it wants to display this in help text.- Parameters:
toValue- The value to use as a default value for this argument.- Returns:
- This continued builder instance.
-
conversionFunction
public <E extends Exception> Argument.ArgumentBuilder<T> conversionFunction(FunctionPotentialException<String, T, E> functionWhichMayThrowException) This constructor is used to override the conversion function in order to wrap the call to theFunction.apply(Object)such that the implementing user can use checked exceptions if they want, without it causing compile time issues. Any exceptions will be wrapped into the reason for anIllegalArgumentException.- Type Parameters:
E- Allowing theFunctionPotentialExceptionto throw an instance of an Exception, as a child reason to an IllegalArgumentException.- Parameters:
functionWhichMayThrowException- An input lambda which may or may not throw an exception. The lambda's single input parameter will be a String which would be the command line argument value. The return type is tied to the typing of the baseArgument<T>. The exception is introspected by the definition of the provided lambda.- Returns:
- This continued builder instance.
-
validationFunction
public <E extends Exception> Argument.ArgumentBuilder<T> validationFunction(FunctionPotentialException<T, Boolean, E> functionWhichMayThrowException) This constructor is used to override the value validation function in order to wrap the call to theFunction.apply(Object)such that the implementing user can use checked exceptions if they want, without it causing compile time issues. Any exceptions will be wrapped into the reason for anIllegalArgumentException.- Type Parameters:
E- Allowing theFunctionPotentialExceptionto throw an instance of an Exception, as a child reason to an IllegalArgumentException.- Parameters:
functionWhichMayThrowException- An input lambda which may or may not throw an exception. The lambda's single input parameter will be the type-safe value, typed against the T of the baseArgument. The return type will be a boolean determining whether the successfully parsed value is within some user-defined acceptable range. The exception is introspected by the definition of the provided lambda.- Returns:
- This continued builder instance.
-
shortOptions
Used to contain all the single character alias' to indicate this option- Returns:
this.
-
longOptions
Used to contain all the word alias' to indicate this option- Returns:
this.
-
mustBeUsedWith
Used to denote other CLI Arguments (by reference to theirArgument.uniqueId) which MUST be present if, and only if, this Argument is found on the CLI.- Returns:
this.
-
mustNotBeUsedWith
Used to denote other CLI Arguments (by reference to theirArgument.uniqueId) which MUST NOT be used in conjunction with this one if, and only if, this Argument is found on the CLI.- Returns:
this.
-
isMandatory
Used to indicate if this argument is mandatory and MUST be provided for the utilising code to function. If you set this value to true, you probably don't want to set a default value.- Returns:
this.
-
shouldShortCircuit
Used to tell a parser that if this argument is detected on the CLI at all, it should ALWAYS be returnable to the caller with all present short circuit args. Ideally ignoring any other constraints, such asArgument.isMandatory= true; or an already parsed argument withArgument.mustBeUsedWithset. This will only take effect, if a short-circuiting argument is found on the command line before another CLI option which would cause the parser to fail.- Returns:
this.
-
valueIsOptional
Used to indicate if the value to this argument can be optional, defaults to false. (e.g. value MUST be provided)- Returns:
this.
-
description
Used to describe the purpose of this Argument and how it should be used.- Returns:
this.
-
defaultValueSet
Used to track if a default value has been set for this argument to be used if no CLI value is found.- Returns:
this.
-
argumentResult
If this argument needs a value, then this should be the fully validated and parsed output of that value.- Returns:
this.
-
build
-
toString
-