MCPcopy Index your code
hub / github.com/coder/coder / externalWorkspaceList

Method externalWorkspaceList

enterprise/cli/externalworkspaces.go:152–220  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

150}
151
152func (r *RootCmd) externalWorkspaceList() *serpent.Command {
153 var (
154 filter cliui.WorkspaceFilter
155 formatter = cliui.NewOutputFormatter(
156 cliui.TableFormat(
157 []agpl.WorkspaceListRow{},
158 []string{
159 "workspace",
160 "template",
161 "status",
162 "healthy",
163 "last built",
164 "current version",
165 "outdated",
166 },
167 ),
168 cliui.JSONFormat(),
169 )
170 )
171 cmd := &serpent.Command{
172 Annotations: map[string]string{
173 "workspaces": "",
174 },
175 Use: "list",
176 Short: "List external workspaces",
177 Aliases: []string{"ls"},
178 Middleware: serpent.Chain(
179 serpent.RequireNArgs(0),
180 ),
181 Handler: func(inv *serpent.Invocation) error {
182 client, err := r.InitClient(inv)
183 if err != nil {
184 return err
185 }
186
187 baseFilter := filter.Filter()
188
189 if baseFilter.FilterQuery == "" {
190 baseFilter.FilterQuery = "has_external_agent:true"
191 } else {
192 baseFilter.FilterQuery += " has_external_agent:true"
193 }
194
195 res, err := agpl.QueryConvertWorkspaces(inv.Context(), client, baseFilter, agpl.WorkspaceListRowFromWorkspace)
196 if err != nil {
197 return err
198 }
199
200 out, err := formatter.Format(inv.Context(), res)
201 if err != nil {
202 return err
203 }
204
205 if out == "" {
206 pretty.Fprintf(inv.Stderr, cliui.DefaultStyles.Prompt, "No workspaces found! Create one:\n")
207 _, _ = fmt.Fprintln(inv.Stderr)
208 _, _ = fmt.Fprintln(inv.Stderr, " "+pretty.Sprint(cliui.DefaultStyles.Code, "coder external-workspaces create <name>"))
209 _, _ = fmt.Fprintln(inv.Stderr)

Callers 1

externalWorkspacesMethod · 0.95

Calls 8

InitClientMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
ContextMethod · 0.65
FormatMethod · 0.65
AttachOptionsMethod · 0.65
FilterMethod · 0.45

Tested by

no test coverage detected