Skip to content

feat: add rich parameters #4311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update deprecated parameter name in CLI
  • Loading branch information
kylecarbs committed Oct 27, 2022
commit 1e05960594328f3440a584446a0ca1e3ba41346e
2 changes: 1 addition & 1 deletion cli/cliui/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/coder/coder/codersdk"
)

func ParameterSchema(cmd *cobra.Command, parameterSchema codersdk.DeprecatedParameterSchema) (string, error) {
func DeprecatedParameterSchema(cmd *cobra.Command, parameterSchema codersdk.DeprecatedParameterSchema) (string, error) {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), Styles.Bold.Render("var."+parameterSchema.Name))
if parameterSchema.Description != "" {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+strings.TrimSpace(strings.Join(strings.Split(parameterSchema.Description, "\n"), "\n "))+"\n")
Expand Down
37 changes: 19 additions & 18 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ func create() *cobra.Command {
}

parameters, err := prepWorkspaceBuild(cmd, client, prepWorkspaceBuildArgs{
Template: template,
ExistingParams: []codersdk.DeprecatedParameter{},
ParameterFile: parameterFile,
NewWorkspaceName: workspaceName,
Template: template,
ExistingDeprecatedParams: []codersdk.DeprecatedParameter{},
ParameterFile: parameterFile,
NewWorkspaceName: workspaceName,
})
if err != nil {
return err
Expand Down Expand Up @@ -170,10 +170,11 @@ func create() *cobra.Command {
}

type prepWorkspaceBuildArgs struct {
Template codersdk.Template
ExistingParams []codersdk.DeprecatedParameter
ParameterFile string
NewWorkspaceName string
Template codersdk.Template
ExistingParams []codersdk.WorkspaceBuildParameter
ExistingDeprecatedParams []codersdk.DeprecatedParameter
ParameterFile string
NewWorkspaceName string
}

// prepWorkspaceBuild will ensure a workspace build will succeed on the latest template version.
Expand All @@ -184,7 +185,7 @@ func prepWorkspaceBuild(cmd *cobra.Command, client *codersdk.Client, args prepWo
if err != nil {
return nil, err
}
parameterSchemas, err := client.DeprecatedTemplateVersionSchema(ctx, templateVersion.ID)
deprecatedParameterSchemas, err := client.DeprecatedTemplateVersionSchema(ctx, templateVersion.ID)
if err != nil {
return nil, err
}
Expand All @@ -201,9 +202,9 @@ func prepWorkspaceBuild(cmd *cobra.Command, client *codersdk.Client, args prepWo
}
}
disclaimerPrinted := false
parameters := make([]codersdk.DeprecatedCreateParameterRequest, 0)
PromptParamLoop:
for _, parameterSchema := range parameterSchemas {
deprecatedParameters := make([]codersdk.DeprecatedCreateParameterRequest, 0)
PromptDeprecatedParamLoop:
for _, parameterSchema := range deprecatedParameterSchemas {
if !parameterSchema.AllowOverrideSource {
continue
}
Expand All @@ -214,21 +215,21 @@ PromptParamLoop:

// Param file is all or nothing
if !useParamFile {
for _, e := range args.ExistingParams {
for _, e := range args.ExistingDeprecatedParams {
if e.Name == parameterSchema.Name {
// If the param already exists, we do not need to prompt it again.
// The workspace scope will reuse params for each build.
continue PromptParamLoop
continue PromptDeprecatedParamLoop
}
}
}

parameterValue, err := getParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
parameterValue, err := getDeprecatedParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
if err != nil {
return nil, err
}

parameters = append(parameters, codersdk.DeprecatedCreateParameterRequest{
deprecatedParameters = append(deprecatedParameters, codersdk.DeprecatedCreateParameterRequest{
Name: parameterSchema.Name,
SourceValue: parameterValue,
SourceScheme: codersdk.DeprecatedParameterSourceSchemeData,
Expand All @@ -241,7 +242,7 @@ PromptParamLoop:
after := time.Now()
dryRun, err := client.CreateTemplateVersionDryRun(cmd.Context(), templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
WorkspaceName: args.NewWorkspaceName,
ParameterValues: parameters,
ParameterValues: deprecatedParameters,
})
if err != nil {
return nil, xerrors.Errorf("begin workspace dry-run: %w", err)
Expand Down Expand Up @@ -281,5 +282,5 @@ PromptParamLoop:
return nil, err
}

return parameters, nil
return deprecatedParameters, nil
}
4 changes: 2 additions & 2 deletions cli/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func createParameterMapFromFile(parameterFile string) (map[string]string, error)

// Returns a parameter value from a given map, if the map exists, else takes input from the user.
// Throws an error if the map exists but does not include a value for the parameter.
func getParameterValueFromMapOrInput(cmd *cobra.Command, parameterMap map[string]string, parameterSchema codersdk.DeprecatedParameterSchema) (string, error) {
func getDeprecatedParameterValueFromMapOrInput(cmd *cobra.Command, parameterMap map[string]string, parameterSchema codersdk.DeprecatedParameterSchema) (string, error) {
var parameterValue string
if parameterMap != nil {
var ok bool
Expand All @@ -48,7 +48,7 @@ func getParameterValueFromMapOrInput(cmd *cobra.Command, parameterMap map[string
}
} else {
var err error
parameterValue, err = cliui.ParameterSchema(cmd, parameterSchema)
parameterValue, err = cliui.DeprecatedParameterSchema(cmd, parameterSchema)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templatecreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
_, _ = fmt.Fprint(cmd.OutOrStdout(), "\r\n")

for _, parameterSchema := range missingSchemas {
parameterValue, err := getParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
parameterValue, err := getDeprecatedParameterValueFromMapOrInput(cmd, parameterMapFromFile, parameterSchema)
if err != nil {
return nil, nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func update() *cobra.Command {
}

parameters, err := prepWorkspaceBuild(cmd, client, prepWorkspaceBuildArgs{
Template: template,
ExistingParams: existingParams,
ParameterFile: parameterFile,
NewWorkspaceName: workspace.Name,
Template: template,
ExistingDeprecatedParams: existingParams,
ParameterFile: parameterFile,
NewWorkspaceName: workspace.Name,
})
if err != nil {
return nil
Expand Down