mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Updating workspace prompts new parameters (#2598)
This commit is contained in:
+32
-2
@@ -6,11 +6,17 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/coder/coder/cli/cliflag"
|
||||
"github.com/coder/coder/codersdk"
|
||||
)
|
||||
|
||||
func update() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
var (
|
||||
parameterFile string
|
||||
alwaysPrompt bool
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Annotations: workspaceCommand,
|
||||
Use: "update",
|
||||
Short: "Update a workspace to the latest template version",
|
||||
@@ -23,7 +29,7 @@ func update() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !workspace.Outdated {
|
||||
if !workspace.Outdated && !alwaysPrompt {
|
||||
_, _ = fmt.Printf("Workspace isn't outdated!\n")
|
||||
return nil
|
||||
}
|
||||
@@ -31,10 +37,30 @@ func update() *cobra.Command {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var existingParams []codersdk.Parameter
|
||||
if !alwaysPrompt {
|
||||
existingParams, err = client.Parameters(cmd.Context(), codersdk.ParameterWorkspace, workspace.ID)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
parameters, err := prepWorkspaceBuild(cmd, client, prepWorkspaceBuildArgs{
|
||||
Template: template,
|
||||
ExistingParams: existingParams,
|
||||
ParameterFile: parameterFile,
|
||||
NewWorkspaceName: workspace.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
before := time.Now()
|
||||
build, err := client.CreateWorkspaceBuild(cmd.Context(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{
|
||||
TemplateVersionID: template.ActiveVersionID,
|
||||
Transition: workspace.LatestBuild.Transition,
|
||||
ParameterValues: parameters,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -53,4 +79,8 @@ func update() *cobra.Command {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().BoolVar(&alwaysPrompt, "always-prompt", false, "Always prompt all parameters. Does not pull parameter values from existing workspace")
|
||||
cliflag.StringVarP(cmd.Flags(), ¶meterFile, "parameter-file", "", "CODER_PARAMETER_FILE", "", "Specify a file path with parameter values.")
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user