/
ls.go
50 lines (40 loc) · 1.15 KB
/
ls.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
package cmd
import (
"fmt"
"github.com/canopytax/ckube/util"
"github.com/spf13/cobra"
)
// lsCmd represents the ls command
var lsCmd = &cobra.Command{
Use: "ls [NAME]",
Aliases: []string{"get"},
Short: "Interactive list of pods",
Long: `Interactive list of pods matching the specified value.
Use arrow keys to navigate and '/' to search the list. Selecting
a pod will print the result of 'kubectl describe [POD]'
Examples:
# List all pods in the current namespace
ckube ls
# List all pods starting with 'nginx'
ckube ls nginx`,
Run: func(cmd *cobra.Command, args []string) {
pods := util.RawK8sOutput(namespace, context, labels, "get", "pods")
if len(args) > 0 {
searchString := args[0]
pods = util.FilterOutput(pods, searchString, false)
}
podInfos := util.CreatePodInfos(pods)
prompt := util.GetPodPrompt(podInfos, "Select a pod for more info. Type '/' to search")
i, _, err := prompt.Run()
if err != nil {
return
}
output := util.RawK8sOutput(namespace, context, labels, "describe", "pod", podInfos[i].Name)
for _, line := range output {
fmt.Println(line)
}
},
}
func init() {
RootCmd.AddCommand(lsCmd)
}