-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
95 lines (79 loc) · 2.14 KB
/
main.go
File metadata and controls
95 lines (79 loc) · 2.14 KB
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
89
90
91
92
93
94
95
package main
// Import this shit for unmarshal yaml
// Import cmd package locally, not start with github.com
// "kctx/cmd" // no need to import
func main() {
// Example:
// args[0] = binary name (ex: "./kctx")
// args[1] = first arg (ex: "ctx" or "ns")
// Get namespace list
// nsList, err := listNamespaces()
// if err != nil {
// fmt.Println("Error getting namespace list:", err)
// return
// } else {
// fmt.Println("Namespace list:", nsList)
// }
// My job done here xD
// Call cobra directly, because we don't need to import cmd package
Execute()
// Comment from here to the end to use cobra cmd
/*
// Get kubeconfig path
kubeconfigPath, err := getKubeconfigPath()
if err != nil {
fmt.Println("Error getting kubeconfig path:", err)
return
}
// Call fucking function from config.go, same main package
config, err := loadConfig(kubeconfigPath)
if err != nil {
fmt.Println("Error loading config:", err)
return
}
// Check args
var action string
if len(os.Args) < 2 {
// Ask user to select action
prompt := promptui.Select{
Label: "Select action",
Items: []string{"Change current context", "Change default namespace"},
}
_, result, err := prompt.Run()
if err != nil {
fmt.Println("Error running promptui:", err)
return
}
// fmt.Println("Your selection: ", result)
if result == "Change current context" {
action = "ctx"
} else if result == "Change default namespace" {
action = "ns"
}
} else {
action = os.Args[1] // Get first fucking arg.
}
switch action {
case "ctx":
// fmt.Println("Change context")
err = switchContext(config, kubeconfigPath)
if err != nil {
fmt.Println("Error running switchContext:", err)
return
} else {
fmt.Println("Successfully switched to context: ", config.CurrentContext)
}
return
case "ns":
// fmt.Println("Change default namespace")
err = switchNamespace(config, kubeconfigPath)
if err != nil {
fmt.Println("Error running switchNamespace:", err)
return
}
return
default:
fmt.Println("Unknown action. Use 'ctx' for change context or 'ns' for change namespace")
}
*/
}