1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/api/client/volume/remove.go

55 lines
1.1 KiB
Go
Raw Normal View History

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",
Long: removeDescription,
Example: removeExample,
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runRemove(dockerCli, args)
},
}
}
func runRemove(dockerCli *client.DockerCli, volumes []string) error {
client := dockerCli.Client()
ctx := context.Background()
status := 0
for _, name := range volumes {
if err := client.VolumeRemove(ctx, name); err != nil {
fmt.Fprintf(dockerCli.Err(), "%s\n", err)
status = 1
continue
}
fmt.Fprintf(dockerCli.Out(), "%s\n", name)
}
if status != 0 {
return cli.StatusError{StatusCode: status}
}
return nil
}
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
`