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

Commit0c75ea6

Browse files
endingwithaliAli Diamond
and
Ali Diamond
authored
feat:coder ls should show possible columns to filter by (#4240)
* added showing columns in help call, need to format to make pretty* finished formatting column strings for print of list /ls commandCo-authored-by: Ali Diamond <user@ali.dev>
1 parentdf7c739 commit0c75ea6

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

‎cli/cliui/table.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
6767
}
6868

6969
// Get the list of table column headers.
70-
headersRaw,err:=typeToTableHeaders(v.Type().Elem())
70+
headersRaw,err:=TypeToTableHeaders(v.Type().Elem())
7171
iferr!=nil {
7272
return"",xerrors.Errorf("get table headers recursively for type %q: %w",v.Type().Elem().String(),err)
7373
}
@@ -207,10 +207,10 @@ func isStructOrStructPointer(t reflect.Type) bool {
207207
returnt.Kind()==reflect.Struct|| (t.Kind()==reflect.Pointer&&t.Elem().Kind()==reflect.Struct)
208208
}
209209

210-
//typeToTableHeaders converts a type to a slice of column names. If the given
210+
//TypeToTableHeaders converts a type to a slice of column names. If the given
211211
// type is invalid (not a struct or a pointer to a struct, has invalid table
212212
// tags, etc.), an error is returned.
213-
functypeToTableHeaders(t reflect.Type) ([]string,error) {
213+
funcTypeToTableHeaders(t reflect.Type) ([]string,error) {
214214
if!isStructOrStructPointer(t) {
215215
returnnil,xerrors.Errorf("typeToTableHeaders called with a non-struct or a non-pointer-to-a-struct type")
216216
}
@@ -235,7 +235,7 @@ func typeToTableHeaders(t reflect.Type) ([]string, error) {
235235
returnnil,xerrors.Errorf("field %q in type %q is marked as recursive but does not contain a struct or a pointer to a struct",field.Name,t.String())
236236
}
237237

238-
childNames,err:=typeToTableHeaders(fieldType)
238+
childNames,err:=TypeToTableHeaders(fieldType)
239239
iferr!=nil {
240240
returnnil,xerrors.Errorf("get child field header names for field %q in type %q: %w",field.Name,fieldType.String(),err)
241241
}

‎cli/list.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cli
22

33
import (
44
"fmt"
5+
"reflect"
6+
"strings"
57
"time"
68

79
"github.com/google/uuid"
@@ -58,10 +60,12 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
5860

5961
funclist()*cobra.Command {
6062
var (
61-
allbool
62-
columns []string
63-
defaultQuery="owner:me"
64-
searchQuerystring
63+
allbool
64+
columns []string
65+
defaultQuery="owner:me"
66+
searchQuerystring
67+
mebool
68+
displayWorkspaces []workspaceListRow
6569
)
6670
cmd:=&cobra.Command{
6771
Annotations:workspaceCommand,
@@ -80,6 +84,14 @@ func list() *cobra.Command {
8084
ifall&&searchQuery==defaultQuery {
8185
filter.FilterQuery=""
8286
}
87+
88+
ifme {
89+
myUser,err:=client.User(cmd.Context(),codersdk.Me)
90+
iferr!=nil {
91+
returnerr
92+
}
93+
filter.Owner=myUser.Username
94+
}
8395
workspaces,err:=client.Workspaces(cmd.Context(),filter)
8496
iferr!=nil {
8597
returnerr
@@ -101,7 +113,7 @@ func list() *cobra.Command {
101113
}
102114

103115
now:=time.Now()
104-
displayWorkspaces:=make([]workspaceListRow,len(workspaces))
116+
displayWorkspaces=make([]workspaceListRow,len(workspaces))
105117
fori,workspace:=rangeworkspaces {
106118
displayWorkspaces[i]=workspaceListRowFromWorkspace(now,usersByID,workspace)
107119
}
@@ -115,10 +127,21 @@ func list() *cobra.Command {
115127
returnerr
116128
},
117129
}
130+
131+
v:=reflect.Indirect(reflect.ValueOf(displayWorkspaces))
132+
availColumns,err:=cliui.TypeToTableHeaders(v.Type().Elem())
133+
iferr!=nil {
134+
panic(err)
135+
}
136+
fori,s:=rangeavailColumns {
137+
availColumns[i]=strings.Replace(s," ","_",-1)
138+
}
139+
columnString:=strings.Join(availColumns[:],", ")
140+
118141
cmd.Flags().BoolVarP(&all,"all","a",false,
119142
"Specifies whether all workspaces will be listed or not.")
120143
cmd.Flags().StringArrayVarP(&columns,"column","c",nil,
121-
"Specify a column to filter in the table.")
122-
cmd.Flags().StringVar(&searchQuery,"search",defaultQuery,"Search for a workspace with a query.")
144+
fmt.Sprintf("Specify a column to filter in the table. Available columns are: %v",columnString))
145+
cmd.Flags().StringVar(&searchQuery,"search","","Search for a workspace with a query.")
123146
returncmd
124147
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp