Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit e76a60e

Browse files
committed
fixup! Add coder envs rm command for removing environments
1 parent 0d0c495 commit e76a60e

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

internal/cmd/envs.go

+19-22
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/manifoldco/promptui"
1313
"github.com/spf13/cobra"
1414
"golang.org/x/sync/errgroup"
15-
"golang.org/x/sync/semaphore"
1615
"golang.org/x/xerrors"
1716
)
1817

@@ -198,7 +197,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
198197
clog.LogSuccess(
199198
"creating environment...",
200199
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),
202201
)
203202

204203
if follow {
@@ -335,45 +334,43 @@ func rmEnvsCommand(user *string) *cobra.Command {
335334
if err != nil {
336335
return err
337336
}
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+
}
341346

342347
var egroup errgroup.Group
348+
var failures int32
343349
for _, envName := range args {
344350
envName := envName
345351
egroup.Go(func() error {
346352
env, err := findEnv(ctx, client, envName, *user)
347353
if err != nil {
354+
atomic.AddInt32(&failures, 1)
348355
clog.Log(err)
349356
return err
350357
}
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-
}
366358
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+
)
368364
clog.Log(err)
369365
return err
370366
}
367+
clog.LogSuccess(fmt.Sprintf("deleted environment %q", env.Name))
371368
return nil
372369
})
373370
}
374371

375372
if err = egroup.Wait(); err != nil {
376-
return xerrors.Errorf("some environment remove operations failed")
373+
return xerrors.Errorf("%d failures emitted", failures)
377374
}
378375
return nil
379376
},

0 commit comments

Comments
 (0)