github.1git.de/docker/cli@v26.1.3+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(cmd.Context(), dockerCli, opts) 30 }, 31 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 32 return completeNames(dockerCli)(cmd, args, toComplete) 33 }, 34 } 35 } 36 37 // RunConfigRemove removes the given Swarm configs. 38 func RunConfigRemove(ctx context.Context, dockerCli command.Cli, opts RemoveOptions) error { 39 client := dockerCli.Client() 40 41 var errs []string 42 43 for _, name := range opts.Names { 44 if err := client.ConfigRemove(ctx, name); err != nil { 45 errs = append(errs, err.Error()) 46 continue 47 } 48 49 fmt.Fprintln(dockerCli.Out(), name) 50 } 51 52 if len(errs) > 0 { 53 return errors.Errorf("%s", strings.Join(errs, "\n")) 54 } 55 56 return nil 57 }