()
| 342 | } |
| 343 | |
| 344 | func (r *RootCmd) listProxies() *serpent.Command { |
| 345 | formatter := cliui.NewOutputFormatter( |
| 346 | cliui.TableFormat([]codersdk.WorkspaceProxy{}, []string{"name", "url", "proxy status"}), |
| 347 | cliui.JSONFormat(), |
| 348 | cliui.ChangeFormatterData(cliui.TextFormat(), func(data any) (any, error) { |
| 349 | resp, ok := data.([]codersdk.WorkspaceProxy) |
| 350 | if !ok { |
| 351 | return nil, xerrors.Errorf("unexpected type %T", data) |
| 352 | } |
| 353 | var str strings.Builder |
| 354 | _, _ = str.WriteString("Workspace Proxies:\n") |
| 355 | sep := "" |
| 356 | for i, proxy := range resp { |
| 357 | _, _ = str.WriteString(sep) |
| 358 | _, _ = str.WriteString(fmt.Sprintf("%d: %s %s %s", i, proxy.Name, proxy.PathAppURL, proxy.Status.Status)) |
| 359 | for _, errMsg := range proxy.Status.Report.Errors { |
| 360 | _, _ = str.WriteString(color.RedString("\n\tErr: %s", errMsg)) |
| 361 | } |
| 362 | for _, warnMsg := range proxy.Status.Report.Errors { |
| 363 | _, _ = str.WriteString(color.YellowString("\n\tWarn: %s", warnMsg)) |
| 364 | } |
| 365 | sep = "\n" |
| 366 | } |
| 367 | return str.String(), nil |
| 368 | }), |
| 369 | ) |
| 370 | |
| 371 | cmd := &serpent.Command{ |
| 372 | Use: "ls", |
| 373 | Aliases: []string{"list"}, |
| 374 | Short: "List all workspace proxies", |
| 375 | Middleware: serpent.Chain( |
| 376 | serpent.RequireNArgs(0), |
| 377 | ), |
| 378 | Handler: func(inv *serpent.Invocation) error { |
| 379 | ctx := inv.Context() |
| 380 | client, err := r.InitClient(inv) |
| 381 | if err != nil { |
| 382 | return err |
| 383 | } |
| 384 | proxies, err := client.WorkspaceProxies(ctx) |
| 385 | if err != nil { |
| 386 | return xerrors.Errorf("list workspace proxies: %w", err) |
| 387 | } |
| 388 | |
| 389 | output, err := formatter.Format(ctx, proxies.Regions) |
| 390 | if err != nil { |
| 391 | return err |
| 392 | } |
| 393 | |
| 394 | if output == "" { |
| 395 | cliui.Infof(inv.Stderr, "No workspace proxies found.") |
| 396 | return nil |
| 397 | } |
| 398 | |
| 399 | _, err = fmt.Fprintln(inv.Stdout, output) |
| 400 | return err |
| 401 | }, |
no test coverage detected