Reactant integrated Picocli into PicocliCommandService.
You can create a command class and extend ReactantCommand, then you can declare your own command just like a normal Picocli command.
For more usage of Picocli, please refer to Picocli Documentation
Also, you can add internal keyword to the command class to avoid exposing it.
@CommandLine.Command(
name = "poke",
mixinStandardHelpOptions = true, // come with default --help option
description = ["Poke someone"]
)
internal class PokeCommand : ReactantCommand() {
@Option(names = {"-a", "--anonymous"}, description = "Hide your name from the poke message")
Since only Component can get the injections of objects, if your command needs to inject other objects, you can inject in the Command Register and pass it through the command class constructor.
@Component
class MyCommandRegister(
private val commandService: PicocliCommandService,
Reactant provided an opinionated tool to manage the permission tree easily,
which aim to avoid the typo of permissions and allow autocomplete permission in your editor.
The permission nodes implemented the toString(), and return prefix + simpleClassName.toLowerCase().
Following is an example of using the permission nodes:
You can call requirePermission(permission) with PermissionNode or String inside the ReactantCommand,
it will throw an exception to stop the execution and warn the command sender.
@CommandLine.Command(name = "eat")
internal class EatFoodCommand : ReactantCommand() {
The behaviour of requireSenderIs(senderClass...) is same as requirePermission,
which will also throw an exception. It can be use as a sender type guard.
@CommandLine.Command(name = "eat")
internal class EatFoodCommand : ReactantCommand() {
override fun execute() {
requireSenderIs(Player::class)
requirePermission(MyPluginPermissions.Food.Eat)
// eat the food here...
}
}
You can also use the shorthands: requireSenderIsPlayer(), requireSenderIsConsole()