SubCommands
SubCommands are a way to have custom behavior when the first argument (or multiple here) is a determined string. Each commands can have SubCommands and each SubCommand should be able to have SubCommands. Here it's done differently, the name of a SubCommand can include spaces, it will slice the arguments correctly.
Defining SubCommands
SubCommands can be defined for commands, to register a SubCommand you have to overwrite the registerSubCommands
method of your command class then use the subCommand
method of the Command
class.
Example :
You can use CommandContext#isCallingASubCommand
to know if you are calling a SubCommand, because calling a SubCommand will still execute the run
method.
Passing options to your SubCommand
You can set the same options of a command to your SubCommands by passing an object before the callback :
Note that your SubCommands and SubCommands aliases can contains spaces in them, it will work.
If you don't put a description for your SubCommand, it will not be shown into the default help command.
Last updated