-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (73 loc) · 1.95 KB
/
main.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
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
79
80
81
82
83
84
85
86
87
88
package main
import (
"errors"
"fmt"
"os"
"github.com/fioncat/kubewrap/cmd/config"
"github.com/fioncat/kubewrap/cmd/cp"
"github.com/fioncat/kubewrap/cmd/exec"
initcmd "github.com/fioncat/kubewrap/cmd/init"
"github.com/fioncat/kubewrap/cmd/#"
"github.com/fioncat/kubewrap/cmd/ns"
"github.com/fioncat/kubewrap/cmd/restart"
"github.com/fioncat/kubewrap/cmd/scale"
"github.com/fioncat/kubewrap/cmd/setimage"
"github.com/fioncat/kubewrap/cmd/show"
sourcecmd "github.com/fioncat/kubewrap/cmd/source"
"github.com/fioncat/kubewrap/pkg/fzf"
"github.com/spf13/cobra"
)
var (
Version string = "N/A"
BuildType string = "N/A"
BuildCommit string = "N/A"
BuildTime string = "N/A"
)
func newCommand() *cobra.Command {
var printBuildInfo bool
c := &cobra.Command{
Use: "kubewrap",
Short: "A wrapper for kubectl, to add more tools",
Version: Version,
SilenceErrors: true,
SilenceUsage: true,
// Completion is impletemented by `init` command, so disable this
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
RunE: func(cmd *cobra.Command, args []string) error {
if printBuildInfo {
fmt.Printf("version: %s\n", Version)
fmt.Printf("type: %s\n", BuildType)
fmt.Printf("commit: %s\n", BuildCommit)
fmt.Printf("time: %s\n", BuildTime)
return nil
}
return cmd.Usage()
},
}
c.Flags().BoolVarP(&printBuildInfo, "build", "b", false, "print build information and exit")
return c
}
func main() {
c := newCommand()
c.AddCommand(config.New())
c.AddCommand(cp.New())
c.AddCommand(exec.New())
c.AddCommand(initcmd.New())
c.AddCommand(login.New())
c.AddCommand(ns.New())
c.AddCommand(restart.New())
c.AddCommand(scale.New())
c.AddCommand(setimage.New())
c.AddCommand(show.New())
c.AddCommand(sourcecmd.New())
err := c.Execute()
if err != nil {
if errors.Is(err, fzf.ErrCanceled) {
os.Exit(fzf.ExitCodeCanceled)
}
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}