Merge pull request #1078 from datawolf/delete-command

Delete: exit with non zero if one of the containers encountered an error
This commit is contained in:
Qiang Huang 2016-10-11 08:51:29 +02:00 committed by GitHub
commit 010274f2f5
1 changed files with 10 additions and 0 deletions

View File

@ -45,6 +45,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
},
},
Action: func(context *cli.Context) error {
hasError := false
if !context.Args().Present() {
return fmt.Errorf("runc: \"delete\" requires a minimum of 1 argument")
}
@ -65,11 +66,13 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
}
fmt.Fprintf(os.Stderr, "container %s is not exist\n", id)
}
hasError = true
continue
}
s, err := container.Status()
if err != nil {
fmt.Fprintf(os.Stderr, "status for %s: %v\n", id, err)
hasError = true
continue
}
switch s {
@ -79,18 +82,25 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
err := killContainer(container)
if err != nil {
fmt.Fprintf(os.Stderr, "kill container %s: %v\n", id, err)
hasError = true
}
default:
if context.Bool("force") {
err := killContainer(container)
if err != nil {
fmt.Fprintf(os.Stderr, "kill container %s: %v\n", id, err)
hasError = true
}
} else {
fmt.Fprintf(os.Stderr, "cannot delete container %s that is not stopped: %s\n", id, s)
hasError = true
}
}
}
if hasError {
return fmt.Errorf("one or more of the container deletions failed")
}
return nil
},
}