Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commitf44bc76

Browse files
committed
Use dedicated Column interface for table formatting nested structs
1 parentdeb23b4 commitf44bc76

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

‎coder-sdk/env.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ type EnvironmentStat struct {
5454
DiskUsedint64`json:"disk_used"`
5555
}
5656

57-
func (eEnvironmentStat)String()string {returnstring(e.ContainerStatus) }
57+
// Column defines how EnvironmentStat should format in as a table column.
58+
func (eEnvironmentStat)Column()string {returnstring(e.ContainerStatus) }
5859

5960
// EnvironmentStatus refers to the states of an environment.
6061
typeEnvironmentStatusstring

‎coder-sdk/tags.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type ImageTag struct {
1818
CreatedAt time.Time`json:"created_at" table:"-"`
1919
}
2020

21-
func (iImageTag)String()string {
21+
// Column defines how ImageTag should format in as a table column.
22+
func (iImageTag)Column()string {
2223
returni.Tag
2324
}
2425

@@ -29,9 +30,8 @@ type OSRelease struct {
2930
HomeURLstring`json:"home_url"`
3031
}
3132

32-
func (oOSRelease)String()string {
33-
returno.PrettyName
34-
}
33+
// Column defines how OSRelease should format in as a table column.
34+
func (oOSRelease)Column()string {returno.PrettyName }
3535

3636
// CreateImageTagReq defines the request parameters for creating a new image tag.
3737
typeCreateImageTagReqstruct {

‎pkg/tablewriter/tablewriter.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import (
1010

1111
conststructFieldTagKey="table"
1212

13+
// Column defines an interface for formatting a type as a column.
14+
typeColumninterface {
15+
Column()string
16+
}
17+
1318
// StructValues tab delimits the values of a given struct.
1419
//
1520
// Tag a field `table:"-"` to hide it from output.
@@ -20,7 +25,12 @@ func StructValues(data interface{}) string {
2025
ifshouldHideField(v.Type().Field(i)) {
2126
continue
2227
}
23-
fmt.Fprintf(s,"%v\t",v.Field(i).Interface())
28+
value:=v.Field(i).Interface()
29+
ifcolumn,ok:=value.(Column);ok {
30+
fmt.Fprintf(s,"%s\t",column.Column())
31+
}else {
32+
fmt.Fprintf(s,"%v\t",value)
33+
}
2434
}
2535
returns.String()
2636
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp