-
Notifications
You must be signed in to change notification settings - Fork 151
/
view.go
47 lines (40 loc) · 966 Bytes
/
view.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
package core
import (
"github.com/scaleway/scaleway-cli/internal/human"
)
// View hydrates human.MarshalOpt
type View struct {
Title string
Fields []*ViewField
Sections []*ViewSection
}
type ViewField struct {
// Label is the string displayed as header or key for a field.
Label string
// FieldName is the key used to retrieve the value from a field (or nested field) of a structure.
FieldName string
}
type ViewSection struct {
Title string
FieldName string
}
func (v *View) getHumanMarshalerOpt() *human.MarshalOpt {
if v == nil {
return nil
}
opt := &human.MarshalOpt{}
for _, field := range v.Fields {
opt.Fields = append(opt.Fields, &human.MarshalFieldOpt{
FieldName: field.FieldName,
Label: field.Label,
})
}
for _, section := range v.Sections {
opt.Sections = append(opt.Sections, &human.MarshalSection{
Title: section.Title,
FieldName: section.FieldName,
})
}
opt.Title = v.Title
return opt
}