github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/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 var errs []string 37 38 for _, name := range opts.names { 39 if err := client.SecretRemove(ctx, name); err != nil { 40 errs = append(errs, err.Error()) 41 continue 42 } 43 44 fmt.Fprintln(dockerCli.Out(), name) 45 } 46 47 if len(errs) > 0 { 48 return fmt.Errorf("%s", strings.Join(errs, "\n")) 49 } 50 51 return nil 52 }