From a001b177d61b646f038494b24dc41892770f4afe Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Thu, 14 Sep 2017 13:56:33 +0000 Subject: [PATCH] We should not be exiting with exit(1) There is cleanup code that will never get run. This code will print out all errors and then return the last error. This should allow for proper cleanup. Also cleanup help to switch usage and description. Signed-off-by: Daniel J Walsh --- cmd/kpod/stop.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/cmd/kpod/stop.go b/cmd/kpod/stop.go index 93eed6f3..a6998a15 100644 --- a/cmd/kpod/stop.go +++ b/cmd/kpod/stop.go @@ -6,7 +6,6 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" - "os" ) var ( @@ -18,15 +17,21 @@ var ( Value: defaultTimeout, }, } - stopDescription = "Stop one or more containers" - stopCommand = cli.Command{ - Name: "stop", - Usage: "Stops one or more running containers. The container name or ID can be used. A timeout to forcibly" + - " stop the container can also be set but defaults to 10 seconds otherwise.", + stopDescription = ` + kpod stop + + Stops one or more running containers. The container name or ID can be used. + A timeout to forcibly stop the container can also be set but defaults to 10 + seconds otherwise. +` + + stopCommand = cli.Command{ + Name: "stop", + Usage: "Stop one or more containers", Description: stopDescription, Flags: stopFlags, Action: stopCmd, - ArgsUsage: "CONTAINER-NAME", + ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]", } ) @@ -50,19 +55,18 @@ func stopCmd(c *cli.Context) error { if err != nil { return errors.Wrapf(err, "could not update list of containers") } - hadError := false + var lastError error for _, container := range c.Args() { cid, err := server.ContainerStop(container, stopTimeout) if err != nil { - hadError = true - logrus.Error(err) + if lastError != nil { + logrus.Error(lastError) + } + lastError = errors.Wrapf(err, "failed to stop %v", container) } else { fmt.Println(cid) } } - if hadError { - os.Exit(1) - } - return nil + return lastError }