(inv *serpent.Invocation, client *codersdk.Client, organization codersdk.Organization)
| 44 | } |
| 45 | |
| 46 | func selectTemplate(inv *serpent.Invocation, client *codersdk.Client, organization codersdk.Organization) (codersdk.Template, error) { |
| 47 | var empty codersdk.Template |
| 48 | ctx := inv.Context() |
| 49 | allTemplates, err := client.TemplatesByOrganization(ctx, organization.ID) |
| 50 | if err != nil { |
| 51 | return empty, xerrors.Errorf("get templates by organization: %w", err) |
| 52 | } |
| 53 | |
| 54 | if len(allTemplates) == 0 { |
| 55 | return empty, xerrors.Errorf("no templates exist in the current organization %q", organization.Name) |
| 56 | } |
| 57 | |
| 58 | opts := make([]string, 0, len(allTemplates)) |
| 59 | for _, template := range allTemplates { |
| 60 | opts = append(opts, template.Name) |
| 61 | } |
| 62 | |
| 63 | selection, err := cliui.Select(inv, cliui.SelectOptions{ |
| 64 | Options: opts, |
| 65 | }) |
| 66 | if err != nil { |
| 67 | return empty, xerrors.Errorf("select template: %w", err) |
| 68 | } |
| 69 | |
| 70 | for _, template := range allTemplates { |
| 71 | if template.Name == selection { |
| 72 | return template, nil |
| 73 | } |
| 74 | } |
| 75 | return empty, xerrors.Errorf("no template selected") |
| 76 | } |
| 77 | |
| 78 | type templateTableRow struct { |
| 79 | // Used by json format: |
no test coverage detected