generated from LinuxSuRen/.github
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroot.go
34 lines (28 loc) · 805 Bytes
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"context"
"fmt"
ext "github.com/linuxsuren/cobra-extension/pkg"
"github.com/linuxsuren/go-cli-alias/pkg"
"github.com/linuxsuren/go-cli-alias/pkg/cmd"
"github.com/spf13/cobra"
"log"
)
func NewRootCommand() (root *cobra.Command) {
root = &cobra.Command{
Use: "ga",
Short: "alias your command lines",
}
var ctx context.Context
if defMgr, err := pkg.GetDefaultAliasMgrWithNameAndInitialData("", []pkg.Alias{
{Name: "al", Command: "alias list"},
}); err == nil {
ctx = context.WithValue(context.Background(), pkg.AliasKey, defMgr)
root.AddCommand(cmd.NewRootCommand(ctx))
cmd.RegisterAliasCommands(ctx, root)
root.AddCommand(ext.NewCompletionCmd(root))
} else {
log.Println(fmt.Errorf("cannot get default alias manager, error: %v", err))
}
return
}