github.com/ali-iotechsys/cli@v20.10.0+incompatible/cli/command/config/remove.go (about) 1 package config 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 // RemoveOptions contains options for the docker config rm command. 15 type RemoveOptions struct { 16 Names []string 17 } 18 19 func newConfigRemoveCommand(dockerCli command.Cli) *cobra.Command { 20 return &cobra.Command{ 21 Use: "rm CONFIG [CONFIG...]", 22 Aliases: []string{"remove"}, 23 Short: "Remove one or more configs", 24 Args: cli.RequiresMinArgs(1), 25 RunE: func(cmd *cobra.Command, args []string) error { 26 opts := RemoveOptions{ 27 Names: args, 28 } 29 return RunConfigRemove(dockerCli, opts) 30 }, 31 } 32 } 33 34 // RunConfigRemove removes the given Swarm configs. 35 func RunConfigRemove(dockerCli command.Cli, opts RemoveOptions) error { 36 client := dockerCli.Client() 37 ctx := context.Background() 38 39 var errs []string 40 41 for _, name := range opts.Names { 42 if err := client.ConfigRemove(ctx, name); err != nil { 43 errs = append(errs, err.Error()) 44 continue 45 } 46 47 fmt.Fprintln(dockerCli.Out(), name) 48 } 49 50 if len(errs) > 0 { 51 return errors.Errorf("%s", strings.Join(errs, "\n")) 52 } 53 54 return nil 55 }