MCPcopy Index your code
hub / github.com/coder/coder / archiveTemplateVersions

Method archiveTemplateVersions

cli/templateversionarchive.go:102–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100}
101
102func (r *RootCmd) archiveTemplateVersions() *serpent.Command {
103 var all serpent.Bool
104 orgContext := NewOrganizationContext()
105 cmd := &serpent.Command{
106 Use: "archive [template-name...] ",
107 Short: "Archive unused or failed template versions from a given template(s)",
108 Options: serpent.OptionSet{
109 cliui.SkipPromptOption(),
110 serpent.Option{
111 Name: "all",
112 Description: "Include all unused template versions. By default, only failed template versions are archived.",
113 Flag: "all",
114 Value: &all,
115 },
116 },
117 Handler: func(inv *serpent.Invocation) error {
118 var (
119 ctx = inv.Context()
120 templateNames = []string{}
121 templates = []codersdk.Template{}
122 )
123 client, err := r.InitClient(inv)
124 if err != nil {
125 return err
126 }
127 organization, err := orgContext.Selected(inv, client)
128 if err != nil {
129 return err
130 }
131
132 if len(inv.Args) > 0 {
133 templateNames = inv.Args
134
135 for _, templateName := range templateNames {
136 template, err := client.TemplateByName(ctx, organization.ID, templateName)
137 if err != nil {
138 return xerrors.Errorf("get template by name: %w", err)
139 }
140 templates = append(templates, template)
141 }
142 } else {
143 template, err := selectTemplate(inv, client, organization)
144 if err != nil {
145 return err
146 }
147
148 templates = append(templates, template)
149 templateNames = append(templateNames, template.Name)
150 }
151
152 // Confirm archive of the template.
153 _, err = cliui.Prompt(inv, cliui.PromptOptions{
154 Text: fmt.Sprintf("Archive template versions of these templates: %s?", pretty.Sprint(cliui.DefaultStyles.Code, strings.Join(templateNames, ", "))),
155 IsConfirm: true,
156 Default: cliui.ConfirmNo,
157 })
158 if err != nil {
159 return err

Callers 1

templatesMethod · 0.95

Calls 14

InitClientMethod · 0.95
SelectedMethod · 0.95
AttachOptionsMethod · 0.95
SkipPromptOptionFunction · 0.92
PromptFunction · 0.92
TimestampFunction · 0.92
NewOrganizationContextFunction · 0.85
selectTemplateFunction · 0.85
ContextMethod · 0.65
TemplateByNameMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected