-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
alias.go
69 lines (57 loc) · 1.42 KB
/
alias.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
69
package render
import (
"fmt"
"strings"
"github.com/derailed/k9s/internal/client"
"github.com/gdamore/tcell"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// Alias renders a aliases to screen.
type Alias struct{}
// ColorerFunc colors a resource row.
func (Alias) ColorerFunc() ColorerFunc {
return func(ns string, _ Header, re RowEvent) tcell.Color {
return tcell.ColorMediumSpringGreen
}
}
// Header returns a header row.
func (Alias) Header(ns string) Header {
return Header{
HeaderColumn{Name: "RESOURCE"},
HeaderColumn{Name: "COMMAND"},
HeaderColumn{Name: "APIGROUP"},
}
}
// Render renders a K8s resource to screen.
// BOZO!! Pass in a row with pre-alloc fields??
func (Alias) Render(o interface{}, ns string, r *Row) error {
a, ok := o.(AliasRes)
if !ok {
return fmt.Errorf("expected AliasRes, but got %T", o)
}
r.ID = a.GVR
gvr := client.NewGVR(a.GVR)
res, grp := gvr.RG()
r.Fields = append(r.Fields,
res,
strings.Join(a.Aliases, ","),
grp,
)
return nil
}
// ----------------------------------------------------------------------------
// Helpers...
// AliasRes represents an alias resource.
type AliasRes struct {
GVR string
Aliases []string
}
// GetObjectKind returns a schema object.
func (AliasRes) GetObjectKind() schema.ObjectKind {
return nil
}
// DeepCopyObject returns a container copy.
func (a AliasRes) DeepCopyObject() runtime.Object {
return a
}