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