(ctx context.Context, client *codersdk.Client, organizationIDs []uuid.UUID, template string)
| 2302 | } |
| 2303 | |
| 2304 | func parseTemplate(ctx context.Context, client *codersdk.Client, organizationIDs []uuid.UUID, template string) (tpl codersdk.Template, err error) { |
| 2305 | if id, err := uuid.Parse(template); err == nil && id != uuid.Nil { |
| 2306 | tpl, err = client.Template(ctx, id) |
| 2307 | if err != nil { |
| 2308 | return tpl, xerrors.Errorf("get template by ID %q: %w", template, err) |
| 2309 | } |
| 2310 | } else { |
| 2311 | // List templates in all orgs until we find a match. |
| 2312 | orgLoop: |
| 2313 | for _, orgID := range organizationIDs { |
| 2314 | tpls, err := client.TemplatesByOrganization(ctx, orgID) |
| 2315 | if err != nil { |
| 2316 | return tpl, xerrors.Errorf("list templates in org %q: %w", orgID, err) |
| 2317 | } |
| 2318 | |
| 2319 | for _, t := range tpls { |
| 2320 | if t.Name == template { |
| 2321 | tpl = t |
| 2322 | break orgLoop |
| 2323 | } |
| 2324 | } |
| 2325 | } |
| 2326 | } |
| 2327 | if tpl.ID == uuid.Nil { |
| 2328 | return tpl, xerrors.Errorf("could not find template %q in any organization", template) |
| 2329 | } |
| 2330 | |
| 2331 | return tpl, nil |
| 2332 | } |
| 2333 | |
| 2334 | func parseTargetRange(name, targets string) (start, end int, err error) { |
| 2335 | if targets == "" { |
no test coverage detected