/
main.go
68 lines (59 loc) · 1.69 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
package main
import (
"fmt"
"os"
"runtime/pprof"
"github.com/bonnefoa/kubectl-fzf/v3/internal/httpserver"
"github.com/bonnefoa/kubectl-fzf/v3/internal/k8s/resourcewatcher"
"github.com/bonnefoa/kubectl-fzf/v3/internal/k8s/store"
"github.com/bonnefoa/kubectl-fzf/v3/internal/kubectlfzfserver"
"github.com/bonnefoa/kubectl-fzf/v3/internal/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)
var (
version = "dev"
gitCommit = "none"
gitBranch = "unknown"
goVersion = "unknown"
buildDate = "unknown"
)
func versionFun(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s\n", version)
fmt.Printf("Git hash: %s\n", gitCommit)
fmt.Printf("Git branch: %s\n", gitBranch)
fmt.Printf("Build date: %s\n", buildDate)
fmt.Printf("Go Version: %s\n", goVersion)
os.Exit(0)
}
func kubectlFzfServerFun(cmd *cobra.Command, args []string) {
kubectlfzfserver.StartKubectlFzfServer()
}
func main() {
var rootCmd = &cobra.Command{
Use: "kubectl_fzf_server",
Run: kubectlFzfServerFun,
}
rootFlags := rootCmd.PersistentFlags()
store.SetStoreConfigCli(rootFlags)
httpserver.SetHttpServerConfigFlags(rootFlags)
resourcewatcher.SetResourceWatcherCli(rootFlags)
util.SetCommonCliFlags(rootFlags, "info")
err := viper.BindPFlags(rootFlags)
util.FatalIf(err)
versionCmd := &cobra.Command{
Use: "version",
Run: versionFun,
Short: "Print command version",
}
rootCmd.AddCommand(versionCmd)
util.ConfigureViper()
cobra.OnInitialize(util.CommonInitialization)
defer pprof.StopCPUProfile()
defer util.DoMemoryProfile()
if err := rootCmd.Execute(); err != nil {
logrus.Fatalf("Root command failed: %v", err)
}
}