-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (55 loc) · 1.24 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
package main
import (
"fmt"
"github.com/mariobris/pecolify"
"os"
"path"
"path/filepath"
)
var files []string
func main() {
// Instanciate pecolify
pf := pecolify.New()
// Pass data to pecolify
kubeDir, exists := os.LookupEnv("KCS_KUBEDIR")
if exists {
searchFiles(kubeDir)
}
//err := filepath.Walk(kubeDir, func(path string, info os.FileInfo, err error) error {
// // We do not want to see directories
// if info.IsDir() {
// return nil
// }
// files = append(files, path)
// return nil
//})
//if err != nil {
// panic(err)
//}
// Append default k8s config file in home dir if exists
homeDir, _ := os.UserHomeDir()
defaultKubeconfig := path.Join(homeDir, ".kube/config")
if _, err := os.Stat(defaultKubeconfig); err == nil {
files = append(files, defaultKubeconfig)
}
// pecolify!
selected, err := pf.Transform(files)
if err != nil {
fmt.Printf("Error was occured: %v\n", err)
return
}
fmt.Printf("export KUBECONFIG=%s\n", selected)
}
func searchFiles(kubeDir string) {
err := filepath.Walk(kubeDir, func(path string, info os.FileInfo, err error) error {
// We do not want to see directories
if info.IsDir() {
return nil
}
files = append(files, path)
return nil
})
if err != nil {
panic(err)
}
}