1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/cli/command/secret/remove.go
Evan Hazlett 70d2cefd51 update secret inspect to support IDs
This updates secret inspect to support inspect by ID in addition to name
as well as inspecting multiple secrets.  This also cleans up the
help text for consistency.

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
2016-11-22 16:01:16 -05:00

48 lines
985 B
Go

package secret
import (
"fmt"
"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
type removeOptions struct {
names []string
}
func newSecretRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
return &cobra.Command{
Use: "rm SECRET [SECRET]",
Short: "Remove a secret",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts := removeOptions{
names: args,
}
return runSecretRemove(dockerCli, opts)
},
}
}
func runSecretRemove(dockerCli *command.DockerCli, opts removeOptions) error {
client := dockerCli.Client()
ctx := context.Background()
ids, err := getCliRequestedSecretIDs(ctx, client, opts.names)
if err != nil {
return err
}
for _, id := range ids {
if err := client.SecretRemove(ctx, id); err != nil {
fmt.Fprintf(dockerCli.Out(), "WARN: %s\n", err)
}
fmt.Fprintln(dockerCli.Out(), id)
}
return nil
}