Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ labctl playground list
And stop a running playground with:

```sh
labctl playground stop <playground-id>
labctl playground stop <playground-ids>
```

### Signing out and deleting the CLI
Expand Down
47 changes: 25 additions & 22 deletions cmd/playground/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/briandowns/spinner"
// "github.com/briandowns/spinner"
"github.com/spf13/cobra"

"github.com/iximiuz/labctl/internal/labcli"
Expand All @@ -14,7 +14,7 @@ import (
const stopCommandTimeout = 5 * time.Minute

type stopOptions struct {
playID string
playIDS []string

quiet bool
}
Expand All @@ -23,13 +23,12 @@ func newStopCommand(cli labcli.CLI) *cobra.Command {
var opts stopOptions

cmd := &cobra.Command{
Use: "stop [flags] <playground-id>",
Use: "stop [flags] <playground-ids>",
Short: `Stop one or more playgrounds`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli.SetQuiet(opts.quiet)

opts.playID = args[0]
opts.playIDS = args

return labcli.WrapStatusError(runStopPlayground(cmd.Context(), cli, &opts))
},
Expand All @@ -49,32 +48,36 @@ func newStopCommand(cli labcli.CLI) *cobra.Command {
}

func runStopPlayground(ctx context.Context, cli labcli.CLI, opts *stopOptions) error {
cli.PrintAux("Stopping playground %s...\n", opts.playID)
for _, playID := range opts.playIDS {
cli.PrintAux("Stopping playground %s...\n", playID)

if err := cli.Client().DeletePlay(ctx, opts.playID); err != nil {
return fmt.Errorf("couldn't delete the playground: %w", err)
}
if err := cli.Client().DeletePlay(ctx, playID); err != nil {
return fmt.Errorf("couldn't delete the playground: %w", err)
}

// s := spinner.New(spinner.CharSets[38], 300*time.Millisecond)
// s.Writer = cli.AuxStream()
// s.Prefix = "Waiting for playground " + playID + " to terminate... "
// s.Start()

s := spinner.New(spinner.CharSets[38], 300*time.Millisecond)
s.Writer = cli.AuxStream()
s.Prefix = "Waiting for playground to terminate... "
s.Start()
ctx, cancel := context.WithTimeout(ctx, stopCommandTimeout)
defer cancel()

ctx, cancel := context.WithTimeout(ctx, stopCommandTimeout)
defer cancel()
// for ctx.Err() == nil {

for ctx.Err() == nil {
if play, err := cli.Client().GetPlay(ctx, opts.playID); err == nil && !play.Active {
s.FinalMSG = "Waiting for playground to terminate... Done.\n"
s.Stop()
if play, err := cli.Client().GetPlay(ctx, playID); err == nil && !play.Active {
// s.FinalMSG = "Waiting for playground " + playID + " to terminate... Done.\n"
// s.Stop()
// time.Sleep(4 * time.Second)
cli.PrintAux("Playground has been stopped.\n")

return nil
}

time.Sleep(2 * time.Second)
}
// }

cli.PrintAux("Playground has been stopped.\n")
// cli.PrintAux("Playground has been stopped.\n")
}

return nil
}