Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa9b230

Browse files
committed
Add "--always-prompt" flag and logging info
1 parent c43aedc commit fa9b230

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

cli/templatecreate.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,6 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
229229
sort.Slice(parameterSchemas, func(i, j int) bool {
230230
return parameterSchemas[i].Name < parameterSchemas[j].Name
231231
})
232-
missingSchemas := make([]codersdk.ParameterSchema, 0)
233-
for _, parameterSchema := range parameterSchemas {
234-
_, ok := valuesBySchemaID[parameterSchema.ID.String()]
235-
if ok {
236-
continue
237-
}
238-
missingSchemas = append(missingSchemas, parameterSchema)
239-
}
240-
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render("This template has required variables! They are scoped to the template, and not viewable after being set.")+"\r\n")
241232

242233
// parameterMapFromFile can be nil if parameter file is not specified
243234
var parameterMapFromFile map[string]string
@@ -248,15 +239,39 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
248239
return nil, nil, err
249240
}
250241
}
251-
for _, parameterSchema := range missingSchemas {
252-
// If the value is in the file, skip trying to reuse the param
242+
243+
// pulled params come from the last template version
244+
pulled := make([]string, 0)
245+
missingSchemas := make([]codersdk.ParameterSchema, 0)
246+
for _, parameterSchema := range parameterSchemas {
247+
_, ok := valuesBySchemaID[parameterSchema.ID.String()]
248+
if ok {
249+
continue
250+
}
251+
252+
// The file values are handled below. So don't handle them here,
253+
// just check if a value is present in the file.
253254
_, fileOk := parameterMapFromFile[parameterSchema.Name]
254255
if inherit, ok := lastParameterValues[parameterSchema.Name]; ok && !fileOk {
256+
// If the value is not in the param file, and can be pulled from the last template version,
257+
// then don't mark it as missing.
255258
parameters = append(parameters, codersdk.CreateParameterRequest{
256259
CopyFromParameter: inherit.ID,
257260
})
261+
pulled = append(pulled, fmt.Sprintf("%q", parameterSchema.Name))
258262
continue
259263
}
264+
265+
missingSchemas = append(missingSchemas, parameterSchema)
266+
}
267+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render("This template has required variables! They are scoped to the template, and not viewable after being set."))
268+
if len(pulled) > 0 {
269+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render(fmt.Sprintf("The following parameter values are being pulled from the latest template version: %s.", strings.Join(pulled, ", "))))
270+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render("Use \"--always-prompt\" flag to change the values."))
271+
}
272+
_, _ = fmt.Fprint(cmd.OutOrStdout(), "\r\n")
273+
274+
for _, parameterSchema := range missingSchemas {
260275
parameterValue, err := getParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
261276
if err != nil {
262277
return nil, nil, err

cli/templateupdate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func templateUpdate() *cobra.Command {
2020
directory string
2121
provisioner string
2222
parameterFile string
23+
alwaysPrompt bool
2324
)
2425

2526
cmd := &cobra.Command{
@@ -73,7 +74,7 @@ func templateUpdate() *cobra.Command {
7374
FileHash: resp.Hash,
7475
ParameterFile: parameterFile,
7576
Template: &template,
76-
ReuseParameters: true,
77+
ReuseParameters: !alwaysPrompt,
7778
})
7879
if err != nil {
7980
return err
@@ -107,6 +108,7 @@ func templateUpdate() *cobra.Command {
107108
cmd.Flags().StringVarP(&directory, "directory", "d", currentDirectory, "Specify the directory to create from")
108109
cmd.Flags().StringVarP(&provisioner, "test.provisioner", "", "terraform", "Customize the provisioner backend")
109110
cmd.Flags().StringVarP(&parameterFile, "parameter-file", "", "", "Specify a file path with parameter values.")
111+
cmd.Flags().BoolVar(&alwaysPrompt, "always-prompt", false, "Always prompt all parameters. Does not pull parameter values from active template version")
110112
cliui.AllowSkipPrompt(cmd)
111113
// This is for testing!
112114
err := cmd.Flags().MarkHidden("test.provisioner")

0 commit comments

Comments
 (0)