Package net.morimekta.console.args
Class Argument
- java.lang.Object
-
- net.morimekta.console.args.BaseArgument
-
- net.morimekta.console.args.Argument
-
public class Argument extends BaseArgument
An argument is a non-optioned CLI argument. Instead of having to match the option name, it may use a predicate to test the value before applying.
-
-
Constructor Summary
Constructors Constructor Description Argument(java.lang.String name, java.lang.String usage, java.util.function.Consumer<java.lang.String> consumer)
Create a default required argument.Argument(java.lang.String name, java.lang.String usage, java.util.function.Consumer<java.lang.String> consumer, java.lang.String defaultValue)
Create a default optional argument with default value.Argument(java.lang.String name, java.lang.String usage, java.util.function.Consumer<java.lang.String> consumer, java.lang.String defaultValue, java.util.function.Predicate<java.lang.String> predicate, boolean repeated, boolean required, boolean hidden)
Create an argument instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
apply(ArgumentList args)
Try to apply to the argument.java.lang.String
getPrefix()
Prefix part of the usage usage message.java.lang.String
getSingleLineUsage()
Get the argument's single line usage string.void
validate()
Called on all the arguments after the parsing is done to validate if all requirements have been passed.-
Methods inherited from class net.morimekta.console.args.BaseArgument
getDefaultValue, getName, getUsage, isHidden, isRepeated, isRequired
-
-
-
-
Constructor Detail
-
Argument
public Argument(java.lang.String name, java.lang.String usage, java.util.function.Consumer<java.lang.String> consumer)
Create a default required argument.- Parameters:
name
- The name of the argument.usage
- The argument usage description.consumer
- The argument consumer.
-
Argument
public Argument(java.lang.String name, java.lang.String usage, java.util.function.Consumer<java.lang.String> consumer, java.lang.String defaultValue)
Create a default optional argument with default value.- Parameters:
name
- The name of the argument.usage
- The argument usage description.consumer
- The argument consumer.defaultValue
- The default value.
-
Argument
public Argument(java.lang.String name, java.lang.String usage, java.util.function.Consumer<java.lang.String> consumer, java.lang.String defaultValue, java.util.function.Predicate<java.lang.String> predicate, boolean repeated, boolean required, boolean hidden)
Create an argument instance.- Parameters:
name
- The name of the argument.usage
- The argument usage description.consumer
- The argument consumer.defaultValue
- The default value.predicate
- A predicate to check if the argument should try to consume the value.repeated
- If the argument is repeated.required
- If the argument is required.hidden
- If the argument is hidden.
-
-
Method Detail
-
getSingleLineUsage
public java.lang.String getSingleLineUsage()
Description copied from class:BaseArgument
Get the argument's single line usage string.- Specified by:
getSingleLineUsage
in classBaseArgument
- Returns:
- The single-line usage string.
-
getPrefix
public java.lang.String getPrefix()
Description copied from class:BaseArgument
Prefix part of the usage usage message.- Specified by:
getPrefix
in classBaseArgument
- Returns:
- The usage prefix.
-
validate
public void validate() throws ArgumentException
Description copied from class:BaseArgument
Called on all the arguments after the parsing is done to validate if all requirements have been passed. Should throw anArgumentException
if is did not validate with the appropriate error message.- Specified by:
validate
in classBaseArgument
- Throws:
ArgumentException
-
apply
public int apply(ArgumentList args)
Description copied from class:BaseArgument
Try to apply to the argument. The method shoud return 0 if the argument is rejected, otherwise the number of argument strings that was consumed.- Specified by:
apply
in classBaseArgument
- Parameters:
args
- The argument list.- Returns:
- The number of args consumed.
-
-