@@ -9,10 +9,12 @@ import (
9
9
10
10
"github.com/daytonaio/daytona/cmd/daytona/config"
11
11
"github.com/daytonaio/daytona/internal/util"
12
- "github.com/daytonaio/daytona/internal/util/apiclient"
12
+ apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient"
13
+ "github.com/daytonaio/daytona/pkg/apiclient"
13
14
workspace_util "github.com/daytonaio/daytona/pkg/cmd/workspace/util"
14
15
"github.com/daytonaio/daytona/pkg/views"
15
16
ide_views "github.com/daytonaio/daytona/pkg/views/ide"
17
+ views_util "github.com/daytonaio/daytona/pkg/views/util"
16
18
"github.com/daytonaio/daytona/pkg/views/workspace/selection"
17
19
18
20
log "github.com/sirupsen/logrus"
@@ -36,7 +38,6 @@ var StartCmd = &cobra.Command{
36
38
GroupID : util .WORKSPACE_GROUP ,
37
39
Run : func (cmd * cobra.Command , args []string ) {
38
40
var workspaceIdOrName string
39
- var message string
40
41
var activeProfile config.Profile
41
42
var ideId string
42
43
var workspaceId string
@@ -53,7 +54,7 @@ var StartCmd = &cobra.Command{
53
54
54
55
ctx := context .Background ()
55
56
56
- apiClient , err := apiclient .GetApiClient (nil )
57
+ apiClient , err := apiclient_util .GetApiClient (nil )
57
58
if err != nil {
58
59
log .Fatal (err )
59
60
}
@@ -68,7 +69,7 @@ var StartCmd = &cobra.Command{
68
69
}
69
70
workspaceList , res , err := apiClient .WorkspaceAPI .ListWorkspaces (ctx ).Execute ()
70
71
if err != nil {
71
- log .Fatal (apiclient .HandleErrorResponse (res , err ))
72
+ log .Fatal (apiclient_util .HandleErrorResponse (res , err ))
72
73
}
73
74
74
75
workspace := selection .GetWorkspaceFromPrompt (workspaceList , "Start" )
@@ -96,7 +97,7 @@ var StartCmd = &cobra.Command{
96
97
97
98
wsInfo , res , err := apiClient .WorkspaceAPI .GetWorkspace (ctx , workspaceIdOrName ).Execute ()
98
99
if err != nil {
99
- log .Fatal (apiclient .HandleErrorResponse (res , err ))
100
+ log .Fatal (apiclient_util .HandleErrorResponse (res , err ))
100
101
}
101
102
workspaceId = wsInfo .Id
102
103
if startProjectFlag == "" {
@@ -110,22 +111,15 @@ var StartCmd = &cobra.Command{
110
111
}
111
112
}
112
113
113
- if startProjectFlag == "" {
114
- message = fmt .Sprintf ("Workspace '%s' is starting" , workspaceIdOrName )
115
- res , err := apiClient .WorkspaceAPI .StartWorkspace (ctx , workspaceIdOrName ).Execute ()
116
- if err != nil {
117
- log .Fatal (apiclient .HandleErrorResponse (res , err ))
118
- }
114
+ err = StartWorkspace (apiClient , workspaceIdOrName , startProjectFlag )
115
+ if err != nil {
116
+ log .Fatal (err )
117
+ }
119
118
120
- views .RenderInfoMessage (message )
119
+ if startProjectFlag == "" {
120
+ views .RenderInfoMessage (fmt .Sprintf ("Workspace '%s' started successfully" , workspaceIdOrName ))
121
121
} else {
122
- message = fmt .Sprintf ("Project '%s' from workspace '%s' is starting" , startProjectFlag , workspaceIdOrName )
123
- res , err := apiClient .WorkspaceAPI .StartProject (ctx , workspaceIdOrName , startProjectFlag ).Execute ()
124
- if err != nil {
125
- log .Fatal (apiclient .HandleErrorResponse (res , err ))
126
- }
127
-
128
- views .RenderInfoMessage (message )
122
+ views .RenderInfoMessage (fmt .Sprintf ("Project '%s' from workspace '%s' started successfully" , startProjectFlag , workspaceIdOrName ))
129
123
130
124
if codeFlag {
131
125
ide_views .RenderIdeOpeningMessage (workspaceIdOrName , startProjectFlag , ideId , ideList )
@@ -159,30 +153,31 @@ func init() {
159
153
160
154
func startAllWorkspaces () error {
161
155
ctx := context .Background ()
162
- apiClient , err := apiclient .GetApiClient (nil )
156
+ apiClient , err := apiclient_util .GetApiClient (nil )
163
157
if err != nil {
164
158
return err
165
159
}
166
160
167
161
workspaceList , res , err := apiClient .WorkspaceAPI .ListWorkspaces (ctx ).Execute ()
168
162
if err != nil {
169
- return apiclient .HandleErrorResponse (res , err )
163
+ return apiclient_util .HandleErrorResponse (res , err )
170
164
}
171
165
172
166
for _ , workspace := range workspaceList {
173
- res , err := apiClient . WorkspaceAPI . StartWorkspace (ctx , workspace .Id ). Execute ( )
167
+ err := StartWorkspace (apiClient , workspace .Name , "" )
174
168
if err != nil {
175
- log .Errorf ("Failed to start workspace %s: %v" , workspace .Name , apiclient . HandleErrorResponse ( res , err ) )
169
+ log .Errorf ("Failed to start workspace %s: %v\n \n " , workspace .Name , err )
176
170
continue
177
171
}
178
- fmt .Printf ("Workspace '%s' is starting\n " , workspace .Name )
172
+
173
+ views .RenderInfoMessage (fmt .Sprintf ("- Workspace '%s' started successfully" , workspace .Name ))
179
174
}
180
175
return nil
181
176
}
182
177
183
178
func getProjectNameCompletions (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
184
179
ctx := context .Background ()
185
- apiClient , err := apiclient .GetApiClient (nil )
180
+ apiClient , err := apiclient_util .GetApiClient (nil )
186
181
if err != nil {
187
182
return nil , cobra .ShellCompDirectiveDefault
188
183
}
@@ -202,7 +197,7 @@ func getProjectNameCompletions(cmd *cobra.Command, args []string, toComplete str
202
197
203
198
func getWorkspaceNameCompletions () ([]string , cobra.ShellCompDirective ) {
204
199
ctx := context .Background ()
205
- apiClient , err := apiclient .GetApiClient (nil )
200
+ apiClient , err := apiclient_util .GetApiClient (nil )
206
201
if err != nil {
207
202
return nil , cobra .ShellCompDirectiveNoFileComp
208
203
}
@@ -222,7 +217,7 @@ func getWorkspaceNameCompletions() ([]string, cobra.ShellCompDirective) {
222
217
223
218
func getAllWorkspacesByState (state WorkspaceState ) ([]string , cobra.ShellCompDirective ) {
224
219
ctx := context .Background ()
225
- apiClient , err := apiclient .GetApiClient (nil )
220
+ apiClient , err := apiclient_util .GetApiClient (nil )
226
221
if err != nil {
227
222
return nil , cobra .ShellCompDirectiveNoFileComp
228
223
}
@@ -248,3 +243,36 @@ func getAllWorkspacesByState(state WorkspaceState) ([]string, cobra.ShellCompDir
248
243
249
244
return choices , cobra .ShellCompDirectiveNoFileComp
250
245
}
246
+
247
+ func StartWorkspace (apiClient * apiclient.APIClient , workspaceId , projectName string ) error {
248
+ ctx := context .Background ()
249
+ var message string
250
+ var startFunc func () error
251
+
252
+ if projectName == "" {
253
+ message = fmt .Sprintf ("Workspace '%s' is starting" , workspaceId )
254
+ startFunc = func () error {
255
+ res , err := apiClient .WorkspaceAPI .StartWorkspace (ctx , workspaceId ).Execute ()
256
+ if err != nil {
257
+ return apiclient_util .HandleErrorResponse (res , err )
258
+ }
259
+ return nil
260
+ }
261
+ } else {
262
+ message = fmt .Sprintf ("Project '%s' from workspace '%s' is starting" , projectName , workspaceId )
263
+ startFunc = func () error {
264
+ res , err := apiClient .WorkspaceAPI .StartProject (ctx , workspaceId , projectName ).Execute ()
265
+ if err != nil {
266
+ return apiclient_util .HandleErrorResponse (res , err )
267
+ }
268
+ return nil
269
+ }
270
+ }
271
+
272
+ err := views_util .WithInlineSpinner (message , startFunc )
273
+ if err != nil {
274
+ return err
275
+ }
276
+
277
+ return nil
278
+ }
0 commit comments