Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 3b6c702

Browse files
committed
Add tab:"omit" struct tag
1 parent 8b1666f commit 3b6c702

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

cmd/coder/secrets.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func makeSecretsCmd() cli.Command {
3939
Action: viewSecret,
4040
},
4141
},
42-
Flags: nil,
4342
}
4443
}
4544

cmd/coder/sync.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import (
1818
func makeSyncCmd() cli.Command {
1919
var init bool
2020
return cli.Command{
21-
Name: "sync",
22-
Usage: "Synchronize local files to a Coder environment",
23-
Description: "Establish a one way directory sync to a Coder environment.",
24-
ArgsUsage: "[local directory] [<env name>:<remote directory>]",
21+
Name: "sync",
22+
Usage: "Establish a one way directory sync to a Coder environment",
23+
ArgsUsage: "[local directory] [<env name>:<remote directory>]",
2524
Before: func(c *cli.Context) error {
2625
if c.Args().Get(0) == "" || c.Args().Get(1) == "" {
2726
return xerrors.Errorf("[local] and [remote] arguments are required")

cmd/coder/users.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func makeUsersCmd() cli.Command {
3131
},
3232
},
3333
},
34-
HelpName: "",
3534
}
3635
}
3736

internal/entclient/secrets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77

88
// Secret describes a Coder secret
99
type Secret struct {
10-
ID string `json:"id"`
10+
ID string `json:"id" tab:"omit"`
1111
Name string `json:"name"`
1212
Value string `json:"value,omitempty"`
1313
Description string `json:"description"`
1414
CreatedAt time.Time `json:"created_at"`
15-
UpdatedAt time.Time `json:"updated_at"`
15+
UpdatedAt time.Time `json:"updated_at" tab:"omit"`
1616
}
1717

1818
// Secrets gets all secrets owned by the authed user

internal/x/xtabwriter/tabwriter.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,44 @@ import (
88
"text/tabwriter"
99
)
1010

11-
// NewWriter chooses reasonable defaults for a human readable output of tabular data
11+
const structFieldTagKey = "tab"
12+
13+
// NewWriter chooses reasonable defaults for a human readable output of tabular data.
1214
func NewWriter() *tabwriter.Writer {
1315
return tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
1416
}
1517

16-
// StructValues tab delimits the values of a given struct
18+
// StructValues tab delimits the values of a given struct.
19+
//
20+
// Tag a field `tab:"omit"` to hide it from output.
1721
func StructValues(data interface{}) string {
1822
v := reflect.ValueOf(data)
1923
s := &strings.Builder{}
2024
for i := 0; i < v.NumField(); i++ {
25+
if shouldHideField(v.Type().Field(i)) {
26+
continue
27+
}
2128
s.WriteString(fmt.Sprintf("%s\t", v.Field(i).Interface()))
2229
}
2330
return s.String()
2431
}
2532

26-
// StructFieldNames tab delimits the field names of a given struct
33+
// StructFieldNames tab delimits the field names of a given struct.
34+
//
35+
// Tag a field `tab:"omit"` to hide it from output.
2736
func StructFieldNames(data interface{}) string {
2837
v := reflect.ValueOf(data)
2938
s := &strings.Builder{}
3039
for i := 0; i < v.NumField(); i++ {
31-
s.WriteString(fmt.Sprintf("%s\t", v.Type().Field(i).Name))
40+
field := v.Type().Field(i)
41+
if shouldHideField(field) {
42+
continue
43+
}
44+
s.WriteString(fmt.Sprintf("%s\t", field.Name))
3245
}
3346
return s.String()
3447
}
48+
49+
func shouldHideField(f reflect.StructField) bool {
50+
return f.Tag.Get(structFieldTagKey) == "omit"
51+
}

0 commit comments

Comments
 (0)