Skip to content

Commit 44ff301

Browse files
authored
syntactically easy way to register commands (#2770)
1 parent 37bb1a8 commit 44ff301

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cmd/cmd.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package cmd
44
import (
55
"fmt"
66
"math/rand"
7+
"sort"
78
"strings"
89
"time"
910

@@ -657,3 +658,16 @@ func Init(opts ...Option) error {
657658
func NewCmd(opts ...Option) Cmd {
658659
return newCmd(opts...)
659660
}
661+
662+
// Register CLI commands
663+
func Register(cmds ...*cli.Command) {
664+
app := DefaultCmd.App()
665+
app.Commands = append(app.Commands, cmds...)
666+
667+
// sort the commands so they're listed in order on the cli
668+
// todo: move this to micro/cli so it's only run when the
669+
// commands are printed during "help"
670+
sort.Slice(app.Commands, func(i, j int) bool {
671+
return app.Commands[i].Name < app.Commands[j].Name
672+
})
673+
}

0 commit comments

Comments
 (0)