()
| 183 | } |
| 184 | |
| 185 | func (r *RootCmd) templateVersionsPromote() *serpent.Command { |
| 186 | var ( |
| 187 | templateName string |
| 188 | templateVersionName string |
| 189 | orgContext = NewOrganizationContext() |
| 190 | ) |
| 191 | cmd := &serpent.Command{ |
| 192 | Use: "promote --template=<template_name> --template-version=<template_version_name>", |
| 193 | Short: "Promote a template version to active.", |
| 194 | Long: "Promote an existing template version to be the active version for the specified template.", |
| 195 | Handler: func(inv *serpent.Invocation) error { |
| 196 | client, err := r.InitClient(inv) |
| 197 | if err != nil { |
| 198 | return err |
| 199 | } |
| 200 | organization, err := orgContext.Selected(inv, client) |
| 201 | if err != nil { |
| 202 | return err |
| 203 | } |
| 204 | |
| 205 | template, err := client.TemplateByName(inv.Context(), organization.ID, templateName) |
| 206 | if err != nil { |
| 207 | return xerrors.Errorf("get template by name: %w", err) |
| 208 | } |
| 209 | |
| 210 | version, err := client.TemplateVersionByName(inv.Context(), template.ID, templateVersionName) |
| 211 | if err != nil { |
| 212 | return xerrors.Errorf("get template version by name: %w", err) |
| 213 | } |
| 214 | |
| 215 | err = client.UpdateActiveTemplateVersion(inv.Context(), template.ID, codersdk.UpdateActiveTemplateVersion{ |
| 216 | ID: version.ID, |
| 217 | }) |
| 218 | if err != nil { |
| 219 | return xerrors.Errorf("update active template version: %w", err) |
| 220 | } |
| 221 | |
| 222 | _, _ = fmt.Fprintf(inv.Stdout, "Successfully promoted version %q to active for template %q\n", templateVersionName, templateName) |
| 223 | return nil |
| 224 | }, |
| 225 | } |
| 226 | |
| 227 | cmd.Options = serpent.OptionSet{ |
| 228 | { |
| 229 | Flag: "template", |
| 230 | FlagShorthand: "t", |
| 231 | Env: "CODER_TEMPLATE_NAME", |
| 232 | Description: "Specify the template name.", |
| 233 | Required: true, |
| 234 | Value: serpent.StringOf(&templateName), |
| 235 | }, |
| 236 | { |
| 237 | Flag: "template-version", |
| 238 | Description: "Specify the template version name to promote.", |
| 239 | Env: "CODER_TEMPLATE_VERSION_NAME", |
| 240 | Required: true, |
| 241 | Value: serpent.StringOf(&templateVersionName), |
| 242 | }, |
no test coverage detected