2016-04-19 12:59:48 -04:00
|
|
|
package volume
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/client"
|
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "rm VOLUME [VOLUME]...",
|
|
|
|
Aliases: []string{"remove"},
|
|
|
|
Short: "Remove a volume",
|
2016-06-20 16:33:53 -04:00
|
|
|
Long: removeDescription,
|
|
|
|
Example: removeExample,
|
2016-05-26 17:57:31 -04:00
|
|
|
Args: cli.RequiresMinArgs(1),
|
2016-04-19 12:59:48 -04:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runRemove(dockerCli, args)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runRemove(dockerCli *client.DockerCli, volumes []string) error {
|
|
|
|
client := dockerCli.Client()
|
2016-05-26 17:57:31 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
status := 0
|
2016-04-19 12:59:48 -04:00
|
|
|
|
|
|
|
for _, name := range volumes {
|
2016-05-26 17:57:31 -04:00
|
|
|
if err := client.VolumeRemove(ctx, name); err != nil {
|
2016-04-19 12:59:48 -04:00
|
|
|
fmt.Fprintf(dockerCli.Err(), "%s\n", err)
|
|
|
|
status = 1
|
|
|
|
continue
|
|
|
|
}
|
2016-07-04 00:02:56 -04:00
|
|
|
fmt.Fprintf(dockerCli.Out(), "%s\n", name)
|
2016-04-19 12:59:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != 0 {
|
|
|
|
return cli.StatusError{StatusCode: status}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-06-20 16:33:53 -04:00
|
|
|
|
|
|
|
var removeDescription = `
|
|
|
|
Removes one or more volumes. You cannot remove a volume that is in use by a container.
|
|
|
|
`
|
|
|
|
|
|
|
|
var removeExample = `
|
|
|
|
$ docker volume rm hello
|
|
|
|
hello
|
|
|
|
`
|