You can register custom console commands using app.RootCmd.AddCommand(cmd), where cmd is a cobra command.

Here is an example:

To run the command you can build your Go application and execute:

Keep in mind that the console commands execute in their own separate app process and run independently from the main serve command (aka. hook and realtime events between different processes are not shared with one another).