Skip to content

Commit 8612825

Browse files
committed
feat(cli): improve update command to add force flag and alias to restart
1 parent 591cefa commit 8612825

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cli/update.go

+20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
func (r *RootCmd) update() *serpent.Command {
1313
var (
14+
force bool
1415
parameterFlags workspaceParameterFlags
1516
bflags buildFlags
1617
)
@@ -29,6 +30,19 @@ func (r *RootCmd) update() *serpent.Command {
2930
if err != nil {
3031
return err
3132
}
33+
34+
// update command with --force flag is used as an alias for restart.
35+
// It can be used to update the workspace parameters for an already up-to-date workspace.
36+
if force {
37+
_, _ = fmt.Fprintf(inv.Stdout, "Restarting %s to update the workspace parameters.\n", workspace.Name)
38+
return r.restart().Handler(inv)
39+
}
40+
41+
if !workspace.Outdated && len(parameterFlags.richParameters) != 0 {
42+
_, _ = fmt.Fprintf(inv.Stdout, "Workspace is up-to-date. Please add --force to update the workspace parameters.\n")
43+
return nil
44+
}
45+
3246
if !workspace.Outdated && !parameterFlags.promptRichParameters && !parameterFlags.promptEphemeralParameters && len(parameterFlags.ephemeralParameters) == 0 {
3347
_, _ = fmt.Fprintf(inv.Stdout, "Workspace is up-to-date.\n")
3448
return nil
@@ -57,5 +71,11 @@ func (r *RootCmd) update() *serpent.Command {
5771

5872
cmd.Options = append(cmd.Options, parameterFlags.allOptions()...)
5973
cmd.Options = append(cmd.Options, bflags.cliOptions()...)
74+
75+
cmd.Options = append(cmd.Options, serpent.Option{
76+
Flag: "force",
77+
Description: "Force the update of the workspace even if it is up-to-date.",
78+
Value: serpent.BoolOf(&force),
79+
})
6080
return cmd
6181
}

0 commit comments

Comments
 (0)