Merge pull request #909 from rhatdan/lastError
We should not be exiting with exit(1)
This commit is contained in:
commit
5e3c53c172
2 changed files with 21 additions and 16 deletions
|
@ -105,7 +105,7 @@ func main() {
|
||||||
if debug {
|
if debug {
|
||||||
logrus.Errorf(err.Error())
|
logrus.Errorf(err.Error())
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(err.Error())
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
}
|
}
|
||||||
cli.OsExiter(1)
|
cli.OsExiter(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-o/libkpod"
|
"github.com/kubernetes-incubator/cri-o/libkpod"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -18,15 +18,21 @@ var (
|
||||||
Value: defaultTimeout,
|
Value: defaultTimeout,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
stopDescription = "Stop one or more containers"
|
stopDescription = `
|
||||||
stopCommand = cli.Command{
|
kpod stop
|
||||||
Name: "stop",
|
|
||||||
Usage: "Stops one or more running containers. The container name or ID can be used. A timeout to forcibly" +
|
Stops one or more running containers. The container name or ID can be used.
|
||||||
" stop the container can also be set but defaults to 10 seconds otherwise.",
|
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,
|
Description: stopDescription,
|
||||||
Flags: stopFlags,
|
Flags: stopFlags,
|
||||||
Action: stopCmd,
|
Action: stopCmd,
|
||||||
ArgsUsage: "CONTAINER-NAME",
|
ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,19 +56,18 @@ func stopCmd(c *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not update list of containers")
|
return errors.Wrapf(err, "could not update list of containers")
|
||||||
}
|
}
|
||||||
hadError := false
|
var lastError error
|
||||||
for _, container := range c.Args() {
|
for _, container := range c.Args() {
|
||||||
cid, err := server.ContainerStop(container, stopTimeout)
|
cid, err := server.ContainerStop(container, stopTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
hadError = true
|
if lastError != nil {
|
||||||
logrus.Error(err)
|
fmt.Fprintln(os.Stderr, lastError)
|
||||||
|
}
|
||||||
|
lastError = errors.Wrapf(err, "failed to stop container %v", container)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(cid)
|
fmt.Println(cid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if hadError {
|
return lastError
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue