github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/cli/command/service/remove.go (about) 1 package service 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/docker/docker/cli" 8 "github.com/docker/docker/cli/command" 9 "github.com/spf13/cobra" 10 "golang.org/x/net/context" 11 ) 12 13 func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { 14 15 cmd := &cobra.Command{ 16 Use: "rm SERVICE [SERVICE...]", 17 Aliases: []string{"remove"}, 18 Short: "Remove one or more services", 19 Args: cli.RequiresMinArgs(1), 20 RunE: func(cmd *cobra.Command, args []string) error { 21 return runRemove(dockerCli, args) 22 }, 23 } 24 cmd.Flags() 25 26 return cmd 27 } 28 29 func runRemove(dockerCli *command.DockerCli, sids []string) error { 30 client := dockerCli.Client() 31 32 ctx := context.Background() 33 34 var errs []string 35 for _, sid := range sids { 36 err := client.ServiceRemove(ctx, sid) 37 if err != nil { 38 errs = append(errs, err.Error()) 39 continue 40 } 41 fmt.Fprintf(dockerCli.Out(), "%s\n", sid) 42 } 43 if len(errs) > 0 { 44 return fmt.Errorf(strings.Join(errs, "\n")) 45 } 46 return nil 47 }