-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolumns.go
111 lines (93 loc) · 1.89 KB
/
columns.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package lanes
import (
"strings"
)
type Column string
type ColumnSet []Column
const (
ColumnIndex Column = "IDX"
ColumnLane = "LANE"
ColumnServer = "SERVER"
ColumnIP = "IP ADDRESS"
ColumnState = "STATE"
ColumnID = "ID"
ColumnSSHIdentity = "SSH_IDENTITY"
ColumnUser = "USER"
ColumnInvalid = ""
)
var DefaultColumnSet = ColumnSet{
ColumnIndex,
ColumnLane,
ColumnServer,
ColumnIP,
ColumnState,
ColumnID,
}
func ParseColumnSet(columns string) (out ColumnSet) {
for _, cn := range strings.Split(columns, ",") {
col := ColumnFromName(cn)
if col == ColumnInvalid {
continue
}
out = append(out, col)
}
return out
}
func ColumnFromName(name string) (c Column) {
switch name {
case string(ColumnIndex):
c = ColumnIndex
case string(ColumnLane):
c = ColumnLane
case string(ColumnServer), "NAME":
c = ColumnServer
case string(ColumnIP), "IP":
c = ColumnIP
case string(ColumnState):
c = ColumnState
case string(ColumnID):
c = ColumnID
case string(ColumnSSHIdentity):
c = ColumnSSHIdentity
case string(ColumnUser):
c = ColumnUser
default:
c = ColumnInvalid
}
return c
}
func GetDefaultColumnList() string {
return DefaultColumnSet.String()
}
func (this ColumnSet) Add(columns ...Column) {
this = append(this, columns...)
}
func (this ColumnSet) Remove(columns ...Column) (sanitized ColumnSet) {
for _, col := range this {
show := true
for _, rem := range columns {
if col == rem {
show = false
break
}
}
if show {
sanitized = append(sanitized, col)
}
}
return sanitized
}
func (this ColumnSet) String() string {
var names []string
for _, col := range this {
var name string
switch col {
case ColumnIP:
name = "IP"
default:
name = string(col)
}
names = append(names, name)
}
return strings.Join(names, ",")
}