github.com/scaleway/scaleway-cli@v1.11.1/pkg/commands/wait.go (about) 1 // Copyright (C) 2015 Scaleway. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE.md file. 4 5 package commands 6 7 import ( 8 "fmt" 9 10 "github.com/Sirupsen/logrus" 11 "github.com/scaleway/scaleway-cli/pkg/api" 12 ) 13 14 // WaitArgs are flags for the `RunWait` function 15 type WaitArgs struct { 16 Servers []string 17 } 18 19 // RunWait is the handler for 'scw wait' 20 func RunWait(ctx CommandContext, args WaitArgs) error { 21 hasError := false 22 for _, needle := range args.Servers { 23 serverIdentifier, err := ctx.API.GetServerID(needle) 24 if err != nil { 25 logrus.Error(err) 26 hasError = true 27 } else { 28 if _, err := api.WaitForServerStopped(ctx.API, serverIdentifier); err != nil { 29 logrus.Errorf("failed to wait for server %s: %v", serverIdentifier, err) 30 hasError = true 31 } 32 } 33 } 34 35 if hasError { 36 return fmt.Errorf("at least 1 server failed to be stopped") 37 } 38 return nil 39 }