()
| 31 | } |
| 32 | |
| 33 | func (r *RootCmd) provisionerJobsList() *serpent.Command { |
| 34 | type provisionerJobRow struct { |
| 35 | codersdk.ProvisionerJob `table:"provisioner_job,recursive_inline,nosort"` |
| 36 | OrganizationName string `json:"organization_name" table:"organization"` |
| 37 | Queue string `json:"-" table:"queue"` |
| 38 | } |
| 39 | |
| 40 | var ( |
| 41 | orgContext = NewOrganizationContext() |
| 42 | formatter = cliui.NewOutputFormatter( |
| 43 | cliui.TableFormat([]provisionerJobRow{}, []string{"created at", "id", "type", "template display name", "status", "queue", "tags"}), |
| 44 | cliui.JSONFormat(), |
| 45 | ) |
| 46 | status []string |
| 47 | limit int64 |
| 48 | initiator string |
| 49 | ) |
| 50 | |
| 51 | cmd := &serpent.Command{ |
| 52 | Use: "list", |
| 53 | Short: "List provisioner jobs", |
| 54 | Aliases: []string{"ls"}, |
| 55 | Middleware: serpent.Chain( |
| 56 | serpent.RequireNArgs(0), |
| 57 | ), |
| 58 | Handler: func(inv *serpent.Invocation) error { |
| 59 | ctx := inv.Context() |
| 60 | client, err := r.InitClient(inv) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | org, err := orgContext.Selected(inv, client) |
| 65 | if err != nil { |
| 66 | return xerrors.Errorf("current organization: %w", err) |
| 67 | } |
| 68 | |
| 69 | if initiator != "" { |
| 70 | user, err := client.User(ctx, initiator) |
| 71 | if err != nil { |
| 72 | return xerrors.Errorf("initiator not found: %s", initiator) |
| 73 | } |
| 74 | initiator = user.ID.String() |
| 75 | } |
| 76 | |
| 77 | jobs, err := client.OrganizationProvisionerJobs(ctx, org.ID, &codersdk.OrganizationProvisionerJobsOptions{ |
| 78 | Status: slice.StringEnums[codersdk.ProvisionerJobStatus](status), |
| 79 | Limit: int(limit), |
| 80 | Initiator: initiator, |
| 81 | }) |
| 82 | if err != nil { |
| 83 | return xerrors.Errorf("list provisioner jobs: %w", err) |
| 84 | } |
| 85 | |
| 86 | if len(jobs) == 0 { |
| 87 | _, _ = fmt.Fprintln(inv.Stdout, "No provisioner jobs found") |
| 88 | return nil |
| 89 | } |
| 90 |
no test coverage detected