-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
78 lines (63 loc) · 1.62 KB
/
main.go
File metadata and controls
78 lines (63 loc) · 1.62 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"embed"
"fmt"
"os"
"github.com/spf13/cobra"
checkcmd "kwdb-playground/cmd/check"
doctorcmd "kwdb-playground/cmd/doctor"
startcmd "kwdb-playground/cmd/start"
"kwdb-playground/cmd/stop"
updatecmd "kwdb-playground/cmd/update"
"kwdb-playground/internal/config"
)
//go:embed dist/* courses/*
var staticFiles embed.FS
// 版本信息通过 -ldflags 注入
var (
Version = "dev"
BuildTime = ""
GitCommit = ""
)
func newRootCmd() *cobra.Command {
root := &cobra.Command{
Use: "kwdb-playground",
Short: "KWDB Playground",
Long: "KWDB Playground",
SilenceUsage: true,
SilenceErrors: true,
Version: fmt.Sprintf("%s (build: %s, commit: %s)", Version, BuildTime, GitCommit),
}
// version 子命令
versionCmd := &cobra.Command{
Use: "version",
Short: "显示版本信息",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("版本: %s 构建时间: %s 提交: %s\n", Version, BuildTime, GitCommit)
},
}
root.AddCommand(versionCmd)
// start 子命令
root.AddCommand(startcmd.NewCommand(staticFiles))
// stop 子命令
root.AddCommand(stop.NewCommand())
// doctor 子命令
root.AddCommand(doctorcmd.NewCommand(staticFiles))
// check 兼容子命令(隐藏)
root.AddCommand(checkcmd.NewCommand(staticFiles))
// update 子命令
root.AddCommand(updatecmd.NewCommand())
return root
}
func main() {
syncRuntimeVersion()
if err := newRootCmd().Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func syncRuntimeVersion() {
if config.Version == "" || config.Version == "dev" {
config.Version = Version
}
}