-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (45 loc) · 1.01 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
package main
import (
"fmt"
"os"
"strings"
)
const KUBECTL_BIN = "kubectl"
var (
//wellKnownDirs = map[string]bool{
// "/usr/bin": true,
// "/usr/local/bin": true,
//}
wellKnownDirs = map[string]bool{
"/tmp": true,
}
)
func main() {
var kubectl_path string
for d := range wellKnownDirs {
if IsFileExists(d + string(os.PathSeparator) + KUBECTL_BIN){
kubectl_path = d + string(os.PathSeparator) + KUBECTL_BIN
}
}
if kubectl_path == "" {
//fmt.Printf("%s found at %s", KUBECTL_BIN, kubectl_path)
path := os.Getenv("PATH")
if path != "" {
for _, d := range strings.Split(path, string(os.PathListSeparator)){
_, ok := wellKnownDirs[d]
if ok {
fmt.Printf("%s skipped as already checked\n", d)
continue
}
if IsFileExists(d + string(os.PathSeparator) + KUBECTL_BIN){
kubectl_path = d + string(os.PathSeparator) + KUBECTL_BIN
}
}
}
}
if kubectl_path == "" {
fmt.Printf("%s binary was not found.", KUBECTL_BIN)
os.Exit(1)
}
ParseAndRunCommand()
}