github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/service/remove.go (about) 1 package service 2 3 import ( 4 "context" 5 "fmt" 6 "strings" 7 8 "github.com/docker/cli/cli" 9 "github.com/docker/cli/cli/command" 10 "github.com/pkg/errors" 11 "github.com/spf13/cobra" 12 ) 13 14 func newRemoveCommand(dockerCli command.Cli) *cobra.Command { 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(cmd.Context(), dockerCli, args) 22 }, 23 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 24 return CompletionFn(dockerCli)(cmd, args, toComplete) 25 }, 26 } 27 cmd.Flags() 28 29 return cmd 30 } 31 32 func runRemove(ctx context.Context, dockerCli command.Cli, sids []string) error { 33 client := dockerCli.Client() 34 35 var errs []string 36 for _, sid := range sids { 37 err := client.ServiceRemove(ctx, sid) 38 if err != nil { 39 errs = append(errs, err.Error()) 40 continue 41 } 42 fmt.Fprintf(dockerCli.Out(), "%s\n", sid) 43 } 44 if len(errs) > 0 { 45 return errors.Errorf(strings.Join(errs, "\n")) 46 } 47 return nil 48 }