1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-08-04 21:42:57 +02:00

syntactically easy way to register commands (#2770)

This commit is contained in:
Asim Aslam
2025-05-18 09:45:49 +01:00
committed by GitHub
parent 37bb1a8ab6
commit 44ff301d2d

View File

@@ -4,6 +4,7 @@ package cmd
import (
"fmt"
"math/rand"
"sort"
"strings"
"time"
@@ -657,3 +658,16 @@ func Init(opts ...Option) error {
func NewCmd(opts ...Option) Cmd {
return newCmd(opts...)
}
// Register CLI commands
func Register(cmds ...*cli.Command) {
app := DefaultCmd.App()
app.Commands = append(app.Commands, cmds...)
// sort the commands so they're listed in order on the cli
// todo: move this to micro/cli so it's only run when the
// commands are printed during "help"
sort.Slice(app.Commands, func(i, j int) bool {
return app.Commands[i].Name < app.Commands[j].Name
})
}