Lanat Help

Argument types

When creating arguments, these must know what kind of value they are expecting to receive. Not only that, but they also have to know how to properly convert the user input into that value.

That's the job of an argument type. An argument type is a class that extends ArgumentType<T>. It defines how to parse a number of strings into a value of type T, and what occurs when the parsing fails, among other things.

Default argument types

Lanat comes with a set of default argument types that you can use out of the box.

StringArgumentType

Parses a single string. Essentially just forwards the user input.

StdinArgumentType

Parses the standard input stream. This is useful for commands that receive input from a pipe.

CounterArgumentType

Receives no input. It's return value is the number of times it has been used.

BooleanArgumentType

Parses a boolean value. Accepts true, false, yes, no, 1 and 0.

ActionArgumentType

Receives no input. It returns true if the argument was used. This type is mostly used for when you want to make an argument execute some code when it is used, but you don't want it to receive any input.

TupleArgumentType

Parses multiple values received from the user by using the argument type provided in the constructor. Returns a T[].

NumberRangeArgumentType

Parses a number within a given range. The range is given in the constructor.

KeyValuesArgumentType

Takes key-value pairs. The key is a string, and the value is of the argument type given in the constructor. The key-value pairs are separated by an equals sign (e.g. key=value).

EnumArgumentType

An argument type that takes a valid enum value.

The user can specify any of the enum values by their names. The names are case-insensitive.

OptListArgumentType

An argument type that restricts a possible value out of a list of values.

TryParseArgumentType

Attempts to parse a string into the type given in the constructor. The type given must have a static valueOf(String)}, parse(String)}, or from(String)} method, or a constructor that takes a string. If none of these are found, an exception will be thrown.

Numeric types

Lanat provides a set of argument types to parse all kinds of numeric values. Some of them are: IntegerArgumentType, LongArgumentType, FloatArgumentType, DoubleArgumentType, etc.

Definition helpers

These argument types provide ways to define new argument types.

FromParseableArgumentType

An argument type that uses a Parseable to parse values. If the parseValues(String[]) method of the given Parseable returns null, an error is added. The error message can be specified in the constructor.

SimpleArgumentType

An argument type that allows to define its behavior by using a builder pattern. This basically provides another way to define an argument type.

Check out how to create argument types for more information on how to create your own argument types.

Last modified: 27 May 2024