@@ -37,32 +37,11 @@ func (r *RootCmd) stop() *serpent.Command {
37
37
if err != nil {
38
38
return err
39
39
}
40
- if workspace .LatestBuild .Job .Status == codersdk .ProvisionerJobPending {
41
- // cliutil.WarnMatchedProvisioners also checks if the job is pending
42
- // but we still want to avoid users spamming multiple builds that will
43
- // not be picked up.
44
- cliui .Warn (inv .Stderr ,"The workspace is already stopping!" )
45
- cliutil .WarnMatchedProvisioners (inv .Stderr ,workspace .LatestBuild .MatchedProvisioners ,workspace .LatestBuild .Job )
46
- if _ ,err := cliui .Prompt (inv , cliui.PromptOptions {
47
- Text :"Enqueue another stop?" ,
48
- IsConfirm :true ,
49
- Default :cliui .ConfirmNo ,
50
- });err != nil {
51
- return err
52
- }
53
- }
54
40
55
- wbr := codersdk.CreateWorkspaceBuildRequest {
56
- Transition :codersdk .WorkspaceTransitionStop ,
57
- }
58
- if bflags .provisionerLogDebug {
59
- wbr .LogLevel = codersdk .ProvisionerLogLevelDebug
60
- }
61
- build ,err := client .CreateWorkspaceBuild (inv .Context (),workspace .ID ,wbr )
41
+ build ,err := stopWorkspace (inv ,client ,workspace ,bflags )
62
42
if err != nil {
63
43
return err
64
44
}
65
- cliutil .WarnMatchedProvisioners (inv .Stderr ,build .MatchedProvisioners ,build .Job )
66
45
67
46
err = cliui .WorkspaceBuild (inv .Context (),inv .Stdout ,client ,build .ID )
68
47
if err != nil {
@@ -71,8 +50,8 @@ func (r *RootCmd) stop() *serpent.Command {
71
50
72
51
_ ,_ = fmt .Fprintf (
73
52
inv .Stdout ,
74
- "\n The %s workspace has been stopped at %s!\n " ,cliui . Keyword ( workspace . Name ),
75
-
53
+ "\n The %s workspace has been stopped at %s!\n " ,
54
+ cliui . Keyword ( workspace . Name ),
76
55
cliui .Timestamp (time .Now ()),
77
56
)
78
57
return nil
@@ -82,3 +61,27 @@ func (r *RootCmd) stop() *serpent.Command {
82
61
83
62
return cmd
84
63
}
64
+
65
+ func stopWorkspace (inv * serpent.Invocation ,client * codersdk.Client ,workspace codersdk.Workspace ,bflags buildFlags ) (codersdk.WorkspaceBuild ,error ) {
66
+ if workspace .LatestBuild .Job .Status == codersdk .ProvisionerJobPending {
67
+ // cliutil.WarnMatchedProvisioners also checks if the job is pending
68
+ // but we still want to avoid users spamming multiple builds that will
69
+ // not be picked up.
70
+ cliui .Warn (inv .Stderr ,"The workspace is already stopping!" )
71
+ cliutil .WarnMatchedProvisioners (inv .Stderr ,workspace .LatestBuild .MatchedProvisioners ,workspace .LatestBuild .Job )
72
+ if _ ,err := cliui .Prompt (inv , cliui.PromptOptions {
73
+ Text :"Enqueue another stop?" ,
74
+ IsConfirm :true ,
75
+ Default :cliui .ConfirmNo ,
76
+ });err != nil {
77
+ return codersdk.WorkspaceBuild {},err
78
+ }
79
+ }
80
+ wbr := codersdk.CreateWorkspaceBuildRequest {
81
+ Transition :codersdk .WorkspaceTransitionStop ,
82
+ }
83
+ if bflags .provisionerLogDebug {
84
+ wbr .LogLevel = codersdk .ProvisionerLogLevelDebug
85
+ }
86
+ return client .CreateWorkspaceBuild (inv .Context (),workspace .ID ,wbr )
87
+ }