@@ -12,7 +12,6 @@ import (
12
12
"github.com/manifoldco/promptui"
13
13
"github.com/spf13/cobra"
14
14
"golang.org/x/sync/errgroup"
15
- "golang.org/x/sync/semaphore"
16
15
"golang.org/x/xerrors"
17
16
)
18
17
@@ -198,7 +197,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
198
197
clog .LogSuccess (
199
198
"creating environment..." ,
200
199
clog .BlankLine ,
201
- clog .Tipf (`run "coder envs watch-build %q " to trail the build logs` , args [ 0 ] ),
200
+ clog .Tipf (`run "coder envs watch-build %s " to trail the build logs` , env . Name ),
202
201
)
203
202
204
203
if follow {
@@ -335,45 +334,43 @@ func rmEnvsCommand(user *string) *cobra.Command {
335
334
if err != nil {
336
335
return err
337
336
}
338
-
339
- // only show one confirmation dialogue at a time
340
- confirmLimiter := semaphore .NewWeighted (1 )
337
+ if ! force {
338
+ confirm := promptui.Prompt {
339
+ Label : fmt .Sprintf ("Delete environments %q? (all data will be lost)" , args ),
340
+ IsConfirm : true ,
341
+ }
342
+ if _ , err := confirm .Run (); err != nil {
343
+ return err
344
+ }
345
+ }
341
346
342
347
var egroup errgroup.Group
348
+ var failures int32
343
349
for _ , envName := range args {
344
350
envName := envName
345
351
egroup .Go (func () error {
346
352
env , err := findEnv (ctx , client , envName , * user )
347
353
if err != nil {
354
+ atomic .AddInt32 (& failures , 1 )
348
355
clog .Log (err )
349
356
return err
350
357
}
351
- if ! force {
352
- confirm := promptui.Prompt {
353
- Label : fmt .Sprintf ("Delete environment \" %s\" ? (all data will be lost)" , env .Name ),
354
- IsConfirm : true ,
355
- }
356
- if err := confirmLimiter .Acquire (ctx , 1 ); err != nil {
357
- return err
358
- }
359
-
360
- if _ , err = confirm .Run (); err != nil {
361
- confirmLimiter .Release (1 )
362
- return xerrors .Errorf ("confirm deletion of environment \" %s\" " , env .Name )
363
- }
364
- confirmLimiter .Release (1 )
365
- }
366
358
if err = client .DeleteEnvironment (cmd .Context (), env .ID ); err != nil {
367
- err = clog .Error (fmt .Sprintf (`failed to delete environment "%s"` , env .Name ), clog .Cause (err .Error ()))
359
+ atomic .AddInt32 (& failures , 1 )
360
+ err = clog .Error (
361
+ fmt .Sprintf (`failed to delete environment "%s"` , env .Name ),
362
+ clog .Causef (err .Error ()),
363
+ )
368
364
clog .Log (err )
369
365
return err
370
366
}
367
+ clog .LogSuccess (fmt .Sprintf ("deleted environment %q" , env .Name ))
371
368
return nil
372
369
})
373
370
}
374
371
375
372
if err = egroup .Wait (); err != nil {
376
- return xerrors .Errorf ("some environment remove operations failed" )
373
+ return xerrors .Errorf ("%d failures emitted" , failures )
377
374
}
378
375
return nil
379
376
},
0 commit comments