Check command usage
It is often useful to know if the user interacted with some specific command. Lanat offers two main ways to check this, each with its own use case.
Provide a callback
When defining a command, you can provide a callback that will be executed if the command is used by the user. The callback will receive the ParseResult object that belongs to the command as a parameter.
var myCommand = new ArgumentParser("MyCommand") {{
// more code here
setOnUsedCallback(result -> {
System.out.println("MyCommand was used!");
});
}};
@Command.Define
class MyCommand extends CommandTemplate {
// more code here
@Override
public void onUsed(ParseResult parseResult) {
System.out.println("MyCommand was used!");
}
}
Using ParseResult
The ParseResult object allows you to check if the command was used with the wasUsed() method:
if (result.wasUsed()) {
System.out.println("Command was used");
}
if (result.getSubResult("subcmd").wasUsed()) {
System.out.println("Sub-command was used");
}
Last modified: 16 November 2025