@@ -95,6 +95,7 @@ func (r *RootCmd) list() *serpent.Command {
95
95
),
96
96
cliui .JSONFormat (),
97
97
)
98
+ sharedWithMe bool
98
99
)
99
100
cmd := & serpent.Command {
100
101
Annotations :workspaceCommand ,
@@ -104,13 +105,36 @@ func (r *RootCmd) list() *serpent.Command {
104
105
Middleware :serpent .Chain (
105
106
serpent .RequireNArgs (0 ),
106
107
),
108
+ Options : serpent.OptionSet {
109
+ {
110
+ Name :"shared-with-me" ,
111
+ Description :"Show workspaces shared with you." ,
112
+ Flag :"shared-with-me" ,
113
+ Value :serpent .BoolOf (& sharedWithMe ),
114
+ Hidden :true ,
115
+ },
116
+ },
107
117
Handler :func (inv * serpent.Invocation )error {
108
118
client ,err := r .InitClient (inv )
109
119
if err != nil {
110
120
return err
111
121
}
112
122
113
- res ,err := QueryConvertWorkspaces (inv .Context (),client ,filter .Filter (),WorkspaceListRowFromWorkspace )
123
+ workspaceFilter := filter .Filter ()
124
+ if sharedWithMe {
125
+ user ,err := client .User (inv .Context (),codersdk .Me )
126
+ if err != nil {
127
+ return xerrors .Errorf ("fetch current user: %w" ,err )
128
+ }
129
+ workspaceFilter .SharedWithUser = user .ID .String ()
130
+
131
+ // Unset the default query that conflicts with the --shared-with-me flag
132
+ if workspaceFilter .FilterQuery == "owner:me" {
133
+ workspaceFilter .FilterQuery = ""
134
+ }
135
+ }
136
+
137
+ res ,err := QueryConvertWorkspaces (inv .Context (),client ,workspaceFilter ,WorkspaceListRowFromWorkspace )
114
138
if err != nil {
115
139
return err
116
140
}