1
Define your Command
@Command.Define
class MyProgram {
@Argument.Define(required = true, positional = true)
public String name;
@Argument.Define(type = String.class)
public Optional<String> surname;
@Argument.Define(names = {"age", "a"}, prefix = Argument.Prefix.PLUS)
public int age = 18;
}
2
Put the stuff together
public static void main(String[] args) {
var myProgram = ArgumentParser.parseFromInto(MyProgram.class, args);
System.out.printf(
"Welcome %s! You are %d years old.%n",
myProgram.name, myProgram.age
);
// if no surname was specified, we'll show "none" instead
System.out.printf("The surname of the user is %s.", myProgram.surname.orElse("none"));
}
3
And use it
$ my-program michael +a20
Welcome michael! You are 20 years old.
The surname of the user is none.
Features
Readable errors
Make the users of your software be glad they made that error. Completely customizable error messages with different error levels.└────────────────── ───── ── ─
Automated help messages
Detailed help messages automatically generated for you, based on the structure of your commands.my-program:
This is the description of my program. What do you think about it? Oh by the way,
don't forget to use the argument!
Description:
Specify the user/s to use.
Shows this message.
The value that matters the most (not really). Hey, this thing is generated
automatically as well!: A high precision floating point number.
Must be between 0.0 and 15.23. (Inclusive)
Sub-Commands:
sub1:
Now this is the description of the subcommand inside the main command.
Here's some more extra information about my program. Really don't know how to fill this out...
Rich text formatting
Use tools that easily allow you to format text in descriptions with colors, and other text formatting when displaying it on the terminal.command.setDescription(
"<color=cyan>Hello <format=b,i>world!<format=reset> "
+ "<format=u>Here's some more <color=black:magenta>text<format=reset>"
)
When setting the description of elements, you can use the formatting tags that Lanat provides you with (As seen above). You are not limited with just coloring or formatting, tags can also be used to embed the description of other elements, for example. Note that new custom tags can be created as well, with their own functionality.
Design your own Argument Types
Effortlessly create your own sub-parsers that later will be used to parse the values an argument receives. Lanat comes with many argument types already made for you.
Heres's an example of how argument types are used. In this case, by
using the
EnumArgumentType
we can create an argument that takes an enum value.
Creating the type
Using the type
enum Option {
ACTIVATE,
DEACTIVATE,
@EnumArgumentType.Default
TOGGLE
}
public class MyCommand extends CommandTemplate {
@Argument.Define
public Option option;
}
Finally, let Lanat take care of the rest! If the user writes the name of the enum value, it will be parsed correctly and you'll get the actual enum value as a result once parsed.
Here's how the argument would look like in the help message generated: