()
| 30 | } |
| 31 | |
| 32 | func (r *RootCmd) provisionerList() *serpent.Command { |
| 33 | type provisionerDaemonRow struct { |
| 34 | codersdk.ProvisionerDaemon `table:"provisioner_daemon,recursive_inline"` |
| 35 | OrganizationName string `json:"organization_name" table:"organization"` |
| 36 | } |
| 37 | var ( |
| 38 | orgContext = NewOrganizationContext() |
| 39 | formatter = cliui.NewOutputFormatter( |
| 40 | cliui.TableFormat([]provisionerDaemonRow{}, []string{"created at", "last seen at", "key name", "name", "version", "status", "tags"}), |
| 41 | cliui.JSONFormat(), |
| 42 | ) |
| 43 | limit int64 |
| 44 | offline bool |
| 45 | status []string |
| 46 | maxAge time.Duration |
| 47 | ) |
| 48 | |
| 49 | cmd := &serpent.Command{ |
| 50 | Use: "list", |
| 51 | Short: "List provisioner daemons in an organization", |
| 52 | Aliases: []string{"ls"}, |
| 53 | Middleware: serpent.Chain( |
| 54 | serpent.RequireNArgs(0), |
| 55 | ), |
| 56 | Handler: func(inv *serpent.Invocation) error { |
| 57 | ctx := inv.Context() |
| 58 | client, err := r.InitClient(inv) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | org, err := orgContext.Selected(inv, client) |
| 63 | if err != nil { |
| 64 | return xerrors.Errorf("current organization: %w", err) |
| 65 | } |
| 66 | |
| 67 | daemons, err := client.OrganizationProvisionerDaemons(ctx, org.ID, &codersdk.OrganizationProvisionerDaemonsOptions{ |
| 68 | Limit: int(limit), |
| 69 | Offline: offline, |
| 70 | Status: slice.StringEnums[codersdk.ProvisionerDaemonStatus](status), |
| 71 | MaxAge: maxAge, |
| 72 | }) |
| 73 | if err != nil { |
| 74 | return xerrors.Errorf("list provisioner daemons: %w", err) |
| 75 | } |
| 76 | |
| 77 | var rows []provisionerDaemonRow |
| 78 | for _, daemon := range daemons { |
| 79 | rows = append(rows, provisionerDaemonRow{ |
| 80 | ProvisionerDaemon: daemon, |
| 81 | OrganizationName: org.HumanName(), |
| 82 | }) |
| 83 | } |
| 84 | |
| 85 | out, err := formatter.Format(ctx, rows) |
| 86 | if err != nil { |
| 87 | return xerrors.Errorf("display provisioner daemons: %w", err) |
| 88 | } |
| 89 |
no test coverage detected