-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathroot.go
More file actions
48 lines (39 loc) · 884 Bytes
/
root.go
File metadata and controls
48 lines (39 loc) · 884 Bytes
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
package cmd
import (
"context"
"fmt"
"os"
"slices"
"github.com/spf13/cobra"
"github.com/castai/cluster-controller/cmd/controller"
"github.com/castai/cluster-controller/cmd/monitor"
"github.com/castai/cluster-controller/cmd/testserver"
)
var rootCmd = &cobra.Command{
Use: "castai-cluster-controller",
}
func Execute(ctx context.Context) {
var cmdFound bool
cmd := rootCmd.Commands()
for _, a := range cmd {
if slices.Contains(os.Args[1:], a.Name()) {
cmdFound = true
}
}
if !cmdFound {
args := append([]string{controller.Use}, os.Args[1:]...)
rootCmd.SetArgs(args)
}
if err := rootCmd.ExecuteContext(ctx); err != nil {
fatal(err)
}
}
func init() {
rootCmd.AddCommand(controller.NewCmd())
rootCmd.AddCommand(monitor.NewCmd())
rootCmd.AddCommand(testserver.NewCmd())
}
func fatal(err error) {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}