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

Commit3b6c702

Browse files
committed
Addtab:"omit" struct tag
1 parent8b1666f commit3b6c702

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
funcmakeSyncCmd() cli.Command {
1919
varinitbool
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
ifc.Args().Get(0)==""||c.Args().Get(1)=="" {
2726
returnxerrors.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
typeSecretstruct {
10-
IDstring`json:"id"`
10+
IDstring`json:"id" tab:"omit"`
1111
Namestring`json:"name"`
1212
Valuestring`json:"value,omitempty"`
1313
Descriptionstring`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+
conststructFieldTagKey="tab"
12+
13+
// NewWriter chooses reasonable defaults for a human readable output of tabular data.
1214
funcNewWriter()*tabwriter.Writer {
1315
returntabwriter.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
funcStructValues(datainterface{})string {
1822
v:=reflect.ValueOf(data)
1923
s:=&strings.Builder{}
2024
fori:=0;i<v.NumField();i++ {
25+
ifshouldHideField(v.Type().Field(i)) {
26+
continue
27+
}
2128
s.WriteString(fmt.Sprintf("%s\t",v.Field(i).Interface()))
2229
}
2330
returns.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
funcStructFieldNames(datainterface{})string {
2837
v:=reflect.ValueOf(data)
2938
s:=&strings.Builder{}
3039
fori:=0;i<v.NumField();i++ {
31-
s.WriteString(fmt.Sprintf("%s\t",v.Type().Field(i).Name))
40+
field:=v.Type().Field(i)
41+
ifshouldHideField(field) {
42+
continue
43+
}
44+
s.WriteString(fmt.Sprintf("%s\t",field.Name))
3245
}
3346
returns.String()
3447
}
48+
49+
funcshouldHideField(f reflect.StructField)bool {
50+
returnf.Tag.Get(structFieldTagKey)=="omit"
51+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp