Flight 2.0.0a
Pre-release
Pre-release
This update introduces subcommands. While I don't feel like the implementation is a clean one, subcommands do appear to work as per my testing.
The help command has not been updated to support subcommands yet.
Executing a command without specifying a subcommand will invoke the top-level command. To make the top-level command send a list of available subcommands, you can do something like;
@Command
fun mycommand(ctx: Context, subcommand: String?) {
val cmd = ctx.invokedCommand as CommandFunction
val sc = buildString {
for (c in cmd.subcommands.values.toSet()) {
appendln("${c.name}: ${c.properties.description}")
}
}
if (subcommand != null) {
ctx.send("`${subcommand}` isn't a valid subcommand. Try one of these:\n$sc")
} else {
ctx.send("Available Subcommands:\n$sc")
}
}
Added
Context.invokedCommand
.- This is an executable, but if the invoked command is a subcommand, this can be cast to
SubCommandFunction
. - The same applies if the invoked command is a top-level command; it can be cast to
CommandFunction
.
- This is an executable, but if the invoked command is a subcommand, this can be cast to
Removed
- Removed
CommandRegistry.registerCommands
shortcuts from CommandClient.
Changed
- Renamed
CommandRegistry.registerCommands
toCommandRegistry.register
. - Moved execution stuff to
Executable
class. This makes it a little more streamlined to execute commands. - Command categories are now detected by package name. This behavior can be changed by overriding
Cog.name()
to return a non-null string.