github.com/openshift/moby-moby@v1.13.2-0.20170601211448-f5ec1e2936dc/cli/command/secret/remove.go (about) 1 package secret 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 type removeOptions struct { 14 names []string 15 } 16 17 func newSecretRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { 18 return &cobra.Command{ 19 Use: "rm SECRET [SECRET...]", 20 Aliases: []string{"remove"}, 21 Short: "Remove one or more secrets", 22 Args: cli.RequiresMinArgs(1), 23 RunE: func(cmd *cobra.Command, args []string) error { 24 opts := removeOptions{ 25 names: args, 26 } 27 return runSecretRemove(dockerCli, opts) 28 }, 29 } 30 } 31 32 func runSecretRemove(dockerCli *command.DockerCli, opts removeOptions) error { 33 client := dockerCli.Client() 34 ctx := context.Background() 35 36 ids, err := getCliRequestedSecretIDs(ctx, client, opts.names) 37 if err != nil { 38 return err 39 } 40 41 var errs []string 42 43 for _, id := range ids { 44 if err := client.SecretRemove(ctx, id); err != nil { 45 errs = append(errs, err.Error()) 46 continue 47 } 48 49 fmt.Fprintln(dockerCli.Out(), id) 50 } 51 52 if len(errs) > 0 { 53 return fmt.Errorf("%s", strings.Join(errs, "\n")) 54 } 55 56 return nil 57 }