This repository was archived by the owner on Aug 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,8 @@ type EnvironmentStat struct {
54
54
DiskUsed int64 `json:"disk_used"`
55
55
}
56
56
57
- func (e EnvironmentStat ) String () string { return string (e .ContainerStatus ) }
57
+ // Column defines how EnvironmentStat should format in as a table column.
58
+ func (e EnvironmentStat ) Column () string { return string (e .ContainerStatus ) }
58
59
59
60
// EnvironmentStatus refers to the states of an environment.
60
61
type EnvironmentStatus string
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ type ImageTag struct {
18
18
CreatedAt time.Time `json:"created_at" table:"-"`
19
19
}
20
20
21
- func (i ImageTag ) String () string {
21
+ // Column defines how ImageTag should format in as a table column.
22
+ func (i ImageTag ) Column () string {
22
23
return i .Tag
23
24
}
24
25
@@ -29,9 +30,8 @@ type OSRelease struct {
29
30
HomeURL string `json:"home_url"`
30
31
}
31
32
32
- func (o OSRelease ) String () string {
33
- return o .PrettyName
34
- }
33
+ // Column defines how OSRelease should format in as a table column.
34
+ func (o OSRelease ) Column () string { return o .PrettyName }
35
35
36
36
// CreateImageTagReq defines the request parameters for creating a new image tag.
37
37
type CreateImageTagReq struct {
Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ import (
10
10
11
11
const structFieldTagKey = "table"
12
12
13
+ // Column defines an interface for formatting a type as a column.
14
+ type Column interface {
15
+ Column () string
16
+ }
17
+
13
18
// StructValues tab delimits the values of a given struct.
14
19
//
15
20
// Tag a field `table:"-"` to hide it from output.
@@ -20,7 +25,12 @@ func StructValues(data interface{}) string {
20
25
if shouldHideField (v .Type ().Field (i )) {
21
26
continue
22
27
}
23
- fmt .Fprintf (s , "%v\t " , v .Field (i ).Interface ())
28
+ value := v .Field (i ).Interface ()
29
+ if column , ok := value .(Column ); ok {
30
+ fmt .Fprintf (s , "%s\t " , column .Column ())
31
+ } else {
32
+ fmt .Fprintf (s , "%v\t " , value )
33
+ }
24
34
}
25
35
return s .String ()
26
36
}
You can’t perform that action at this time.
0 commit comments