From 34be688f1bd2136a34804aa71d0a639ee4f7ffe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Doma=C5=84ski?= Date: Sun, 4 Aug 2024 15:34:29 +0200 Subject: [PATCH 1/2] Attempt to stop one or more labs --- cmd/playground/stop.go | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/cmd/playground/stop.go b/cmd/playground/stop.go index 4e75d68..33ce774 100644 --- a/cmd/playground/stop.go +++ b/cmd/playground/stop.go @@ -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" @@ -14,7 +14,7 @@ import ( const stopCommandTimeout = 5 * time.Minute type stopOptions struct { - playID string + playIDS []string quiet bool } @@ -23,13 +23,12 @@ func newStopCommand(cli labcli.CLI) *cobra.Command { var opts stopOptions cmd := &cobra.Command{ - Use: "stop [flags] ", + Use: "stop [flags] ", 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)) }, @@ -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 } From 3f14e87f18d2df21ef7230d10c417ce3bd08f21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Doma=C5=84ski?= Date: Sun, 4 Aug 2024 21:06:03 +0200 Subject: [PATCH 2/2] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 834b366..f409d0c 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ labctl playground list And stop a running playground with: ```sh -labctl playground stop +labctl playground stop ``` ### Signing out and deleting the CLI