Skip to content

Commit 1e05960

Browse files
committed
Update deprecated parameter name in CLI
1 parent 022eec8 commit 1e05960

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

cli/cliui/parameter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/coder/coder/codersdk"
1111
)
1212

13-
func ParameterSchema(cmd *cobra.Command, parameterSchema codersdk.DeprecatedParameterSchema) (string, error) {
13+
func DeprecatedParameterSchema(cmd *cobra.Command, parameterSchema codersdk.DeprecatedParameterSchema) (string, error) {
1414
_, _ = fmt.Fprintln(cmd.OutOrStdout(), Styles.Bold.Render("var."+parameterSchema.Name))
1515
if parameterSchema.Description != "" {
1616
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+strings.TrimSpace(strings.Join(strings.Split(parameterSchema.Description, "\n"), "\n "))+"\n")

cli/create.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ func create() *cobra.Command {
122122
}
123123

124124
parameters, err := prepWorkspaceBuild(cmd, client, prepWorkspaceBuildArgs{
125-
Template: template,
126-
ExistingParams: []codersdk.DeprecatedParameter{},
127-
ParameterFile: parameterFile,
128-
NewWorkspaceName: workspaceName,
125+
Template: template,
126+
ExistingDeprecatedParams: []codersdk.DeprecatedParameter{},
127+
ParameterFile: parameterFile,
128+
NewWorkspaceName: workspaceName,
129129
})
130130
if err != nil {
131131
return err
@@ -170,10 +170,11 @@ func create() *cobra.Command {
170170
}
171171

172172
type prepWorkspaceBuildArgs struct {
173-
Template codersdk.Template
174-
ExistingParams []codersdk.DeprecatedParameter
175-
ParameterFile string
176-
NewWorkspaceName string
173+
Template codersdk.Template
174+
ExistingParams []codersdk.WorkspaceBuildParameter
175+
ExistingDeprecatedParams []codersdk.DeprecatedParameter
176+
ParameterFile string
177+
NewWorkspaceName string
177178
}
178179

179180
// prepWorkspaceBuild will ensure a workspace build will succeed on the latest template version.
@@ -184,7 +185,7 @@ func prepWorkspaceBuild(cmd *cobra.Command, client *codersdk.Client, args prepWo
184185
if err != nil {
185186
return nil, err
186187
}
187-
parameterSchemas, err := client.DeprecatedTemplateVersionSchema(ctx, templateVersion.ID)
188+
deprecatedParameterSchemas, err := client.DeprecatedTemplateVersionSchema(ctx, templateVersion.ID)
188189
if err != nil {
189190
return nil, err
190191
}
@@ -201,9 +202,9 @@ func prepWorkspaceBuild(cmd *cobra.Command, client *codersdk.Client, args prepWo
201202
}
202203
}
203204
disclaimerPrinted := false
204-
parameters := make([]codersdk.DeprecatedCreateParameterRequest, 0)
205-
PromptParamLoop:
206-
for _, parameterSchema := range parameterSchemas {
205+
deprecatedParameters := make([]codersdk.DeprecatedCreateParameterRequest, 0)
206+
PromptDeprecatedParamLoop:
207+
for _, parameterSchema := range deprecatedParameterSchemas {
207208
if !parameterSchema.AllowOverrideSource {
208209
continue
209210
}
@@ -214,21 +215,21 @@ PromptParamLoop:
214215

215216
// Param file is all or nothing
216217
if !useParamFile {
217-
for _, e := range args.ExistingParams {
218+
for _, e := range args.ExistingDeprecatedParams {
218219
if e.Name == parameterSchema.Name {
219220
// If the param already exists, we do not need to prompt it again.
220221
// The workspace scope will reuse params for each build.
221-
continue PromptParamLoop
222+
continue PromptDeprecatedParamLoop
222223
}
223224
}
224225
}
225226

226-
parameterValue, err := getParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
227+
parameterValue, err := getDeprecatedParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
227228
if err != nil {
228229
return nil, err
229230
}
230231

231-
parameters = append(parameters, codersdk.DeprecatedCreateParameterRequest{
232+
deprecatedParameters = append(deprecatedParameters, codersdk.DeprecatedCreateParameterRequest{
232233
Name: parameterSchema.Name,
233234
SourceValue: parameterValue,
234235
SourceScheme: codersdk.DeprecatedParameterSourceSchemeData,
@@ -241,7 +242,7 @@ PromptParamLoop:
241242
after := time.Now()
242243
dryRun, err := client.CreateTemplateVersionDryRun(cmd.Context(), templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
243244
WorkspaceName: args.NewWorkspaceName,
244-
ParameterValues: parameters,
245+
ParameterValues: deprecatedParameters,
245246
})
246247
if err != nil {
247248
return nil, xerrors.Errorf("begin workspace dry-run: %w", err)
@@ -281,5 +282,5 @@ PromptParamLoop:
281282
return nil, err
282283
}
283284

284-
return parameters, nil
285+
return deprecatedParameters, nil
285286
}

cli/parameter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func createParameterMapFromFile(parameterFile string) (map[string]string, error)
3838

3939
// Returns a parameter value from a given map, if the map exists, else takes input from the user.
4040
// Throws an error if the map exists but does not include a value for the parameter.
41-
func getParameterValueFromMapOrInput(cmd *cobra.Command, parameterMap map[string]string, parameterSchema codersdk.DeprecatedParameterSchema) (string, error) {
41+
func getDeprecatedParameterValueFromMapOrInput(cmd *cobra.Command, parameterMap map[string]string, parameterSchema codersdk.DeprecatedParameterSchema) (string, error) {
4242
var parameterValue string
4343
if parameterMap != nil {
4444
var ok bool
@@ -48,7 +48,7 @@ func getParameterValueFromMapOrInput(cmd *cobra.Command, parameterMap map[string
4848
}
4949
} else {
5050
var err error
51-
parameterValue, err = cliui.ParameterSchema(cmd, parameterSchema)
51+
parameterValue, err = cliui.DeprecatedParameterSchema(cmd, parameterSchema)
5252
if err != nil {
5353
return "", err
5454
}

cli/templatecreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
276276
_, _ = fmt.Fprint(cmd.OutOrStdout(), "\r\n")
277277

278278
for _, parameterSchema := range missingSchemas {
279-
parameterValue, err := getParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
279+
parameterValue, err := getDeprecatedParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
280280
if err != nil {
281281
return nil, nil, err
282282
}

cli/update.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func update() *cobra.Command {
4848
}
4949

5050
parameters, err := prepWorkspaceBuild(cmd, client, prepWorkspaceBuildArgs{
51-
Template: template,
52-
ExistingParams: existingParams,
53-
ParameterFile: parameterFile,
54-
NewWorkspaceName: workspace.Name,
51+
Template: template,
52+
ExistingDeprecatedParams: existingParams,
53+
ParameterFile: parameterFile,
54+
NewWorkspaceName: workspace.Name,
5555
})
5656
if err != nil {
5757
return nil

0 commit comments

Comments
 (0)