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

Commit4b1da9b

Browse files
authored
feat(cli): preserve table column order (#16843)
Fixes:#16055
1 parent075e5f4 commit4b1da9b

11 files changed

+42
-16
lines changed

‎cli/cliui/table.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,33 @@ func Table() table.Writer {
3131
// e.g. `[]any{someRow, TableSeparator, someRow}`
3232
typeTableSeparatorstruct{}
3333

34-
// filterTableColumns returns configurations to hide columns
34+
// filterHeaders filters the headers to only include the columns
35+
// that are provided in the array. If the array is empty, all
36+
// headers are included.
37+
funcfilterHeaders(header table.Row,columns []string) table.Row {
38+
iflen(columns)==0 {
39+
returnheader
40+
}
41+
42+
filteredHeaders:=make(table.Row,len(columns))
43+
fori,column:=rangecolumns {
44+
column=strings.ReplaceAll(column,"_"," ")
45+
46+
for_,headerTextRaw:=rangeheader {
47+
headerText,_:=headerTextRaw.(string)
48+
ifstrings.EqualFold(column,headerText) {
49+
filteredHeaders[i]=headerText
50+
break
51+
}
52+
}
53+
}
54+
returnfilteredHeaders
55+
}
56+
57+
// createColumnConfigs returns configuration to hide columns
3558
// that are not provided in the array. If the array is empty,
3659
// no filtering will occur!
37-
funcfilterTableColumns(header table.Row,columns []string) []table.ColumnConfig {
60+
funccreateColumnConfigs(header table.Row,columns []string) []table.ColumnConfig {
3861
iflen(columns)==0 {
3962
returnnil
4063
}
@@ -157,10 +180,13 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
157180
funcrenderTable(outany,sortstring,headers table.Row,filterColumns []string) (string,error) {
158181
v:=reflect.Indirect(reflect.ValueOf(out))
159182

183+
headers=filterHeaders(headers,filterColumns)
184+
columnConfigs:=createColumnConfigs(headers,filterColumns)
185+
160186
// Setup the table formatter.
161187
tw:=Table()
162188
tw.AppendHeader(headers)
163-
tw.SetColumnConfigs(filterTableColumns(headers,filterColumns))
189+
tw.SetColumnConfigs(columnConfigs)
164190
ifsort!="" {
165191
tw.SortBy([]table.SortBy{{
166192
Name:sort,

‎cli/provisionerjobs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (r *RootCmd) provisionerJobsList() *serpent.Command {
4141
client=new(codersdk.Client)
4242
orgContext=NewOrganizationContext()
4343
formatter=cliui.NewOutputFormatter(
44-
cliui.TableFormat([]provisionerJobRow{}, []string{"created at","id","organization","status","type","queue","tags"}),
44+
cliui.TableFormat([]provisionerJobRow{}, []string{"created at","id","type","template display name","status","queue","tags"}),
4545
cliui.JSONFormat(),
4646
)
4747
status []string

‎cli/provisioners.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (r *RootCmd) provisionerList() *serpent.Command {
3636
client=new(codersdk.Client)
3737
orgContext=NewOrganizationContext()
3838
formatter=cliui.NewOutputFormatter(
39-
cliui.TableFormat([]provisionerDaemonRow{}, []string{"name","organization","status","key name","created at","last seen at","version","tags"}),
39+
cliui.TableFormat([]provisionerDaemonRow{}, []string{"created at","last seen at","key name","name","version","status","tags"}),
4040
cliui.JSONFormat(),
4141
)
4242
limitint64
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
IDCREATED ATSTATUSTAGS TYPEORGANIZATION QUEUE
2-
==========[version job ID]==============[timestamp]===== succeeded map[owner: scope:organization] template_version_import Coder
3-
======[workspace build job ID]====== ====[timestamp]===== succeeded map[owner: scope:organization] workspace_buildCoder
1+
CREATED ATIDTYPETEMPLATE DISPLAY NAME STATUSQUEUE TAGS
2+
====[timestamp]===============[version job ID]========== template_version_import succeeded map[owner: scope:organization]
3+
====[timestamp]===== ======[workspace build job ID]====== workspace_build succeeded map[owner: scope:organization]

‎cli/testdata/coder_provisioner_jobs_list_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ OPTIONS:
1111
-O, --org string, $CODER_ORGANIZATION
1212
Select which organization (uuid or name) to use.
1313

14-
-c, --column [id|created at|started at|completed at|canceled at|error|error code|status|worker id|file id|tags|queue position|queue size|organization id|template version id|workspace build id|type|available workers|template version name|template id|template name|template display name|template icon|workspace id|workspace name|organization|queue] (default: created at,id,organization,status,type,queue,tags)
14+
-c, --column [id|created at|started at|completed at|canceled at|error|error code|status|worker id|file id|tags|queue position|queue size|organization id|template version id|workspace build id|type|available workers|template version name|template id|template name|template display name|template icon|workspace id|workspace name|organization|queue] (default: created at,id,type,template display name,status,queue,tags)
1515
Columns to display in table output.
1616

1717
-l, --limit int, $CODER_PROVISIONER_JOB_LIST_LIMIT (default: 50)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
CREATED AT LAST SEEN AT NAMEVERSIONTAGSKEY NAME STATUS ORGANIZATION
2-
====[timestamp]===== ====[timestamp]===== test v0.0.0-devel map[owner: scope:organization] built-in idle Coder
1+
CREATED AT LAST SEEN ATKEYNAMENAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]=====built-intest v0.0.0-develidlemap[owner: scope:organization]

‎cli/testdata/coder_provisioner_list_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ OPTIONS:
1111
-O, --org string, $CODER_ORGANIZATION
1212
Select which organization (uuid or name) to use.
1313

14-
-c, --column [id|organization id|created at|last seen at|name|version|api version|tags|key name|status|current job id|current job status|current job template name|current job template icon|current job template display name|previous job id|previous job status|previous job template name|previous job template icon|previous job template display name|organization] (default:name,organization,status,key name,created at,last seen at,version,tags)
14+
-c, --column [id|organization id|created at|last seen at|name|version|api version|tags|key name|status|current job id|current job status|current job template name|current job template icon|current job template display name|previous job id|previous job status|previous job template name|previous job template icon|previous job template display name|organization] (default: created at,last seen at,key name,name,version,status,tags)
1515
Columns to display in table output.
1616

1717
-l, --limit int, $CODER_PROVISIONER_LIST_LIMIT (default: 50)

‎docs/reference/cli/provisioner_jobs_list.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎docs/reference/cli/provisioner_list.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎enterprise/cli/testdata/coder_provisioner_jobs_list_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ OPTIONS:
1111
-O, --org string, $CODER_ORGANIZATION
1212
Select which organization (uuid or name) to use.
1313

14-
-c, --column [id|created at|started at|completed at|canceled at|error|error code|status|worker id|file id|tags|queue position|queue size|organization id|template version id|workspace build id|type|available workers|template version name|template id|template name|template display name|template icon|workspace id|workspace name|organization|queue] (default: created at,id,organization,status,type,queue,tags)
14+
-c, --column [id|created at|started at|completed at|canceled at|error|error code|status|worker id|file id|tags|queue position|queue size|organization id|template version id|workspace build id|type|available workers|template version name|template id|template name|template display name|template icon|workspace id|workspace name|organization|queue] (default: created at,id,type,template display name,status,queue,tags)
1515
Columns to display in table output.
1616

1717
-l, --limit int, $CODER_PROVISIONER_JOB_LIST_LIMIT (default: 50)

‎enterprise/cli/testdata/coder_provisioner_list_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ OPTIONS:
1111
-O, --org string, $CODER_ORGANIZATION
1212
Select which organization (uuid or name) to use.
1313

14-
-c, --column [id|organization id|created at|last seen at|name|version|api version|tags|key name|status|current job id|current job status|current job template name|current job template icon|current job template display name|previous job id|previous job status|previous job template name|previous job template icon|previous job template display name|organization] (default:name,organization,status,key name,created at,last seen at,version,tags)
14+
-c, --column [id|organization id|created at|last seen at|name|version|api version|tags|key name|status|current job id|current job status|current job template name|current job template icon|current job template display name|previous job id|previous job status|previous job template name|previous job template icon|previous job template display name|organization] (default: created at,last seen at,key name,name,version,status,tags)
1515
Columns to display in table output.
1616

1717
-l, --limit int, $CODER_PROVISIONER_LIST_LIMIT (default: 50)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp