From d6490e5de964157aa34c360468a7c872689f7520 Mon Sep 17 00:00:00 2001 From: allencloud Date: Tue, 6 Dec 2016 00:08:43 +0800 Subject: [PATCH] make secret ls support filters in CLI Signed-off-by: allencloud --- command/secret/ls.go | 7 +++++-- command/service/parse.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/command/secret/ls.go b/command/secret/ls.go index 211ebceb5f..1d60ff7c4d 100644 --- a/command/secret/ls.go +++ b/command/secret/ls.go @@ -5,6 +5,7 @@ import ( "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/formatter" + "github.com/docker/docker/opts" "github.com/spf13/cobra" "golang.org/x/net/context" ) @@ -12,10 +13,11 @@ import ( type listOptions struct { quiet bool format string + filter opts.FilterOpt } func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := listOptions{} + opts := listOptions{filter: opts.NewFilterOpt()} cmd := &cobra.Command{ Use: "ls [OPTIONS]", @@ -30,6 +32,7 @@ func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") flags.StringVarP(&opts.format, "format", "", "", "Pretty-print secrets using a Go template") + flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") return cmd } @@ -38,7 +41,7 @@ func runSecretList(dockerCli *command.DockerCli, opts listOptions) error { client := dockerCli.Client() ctx := context.Background() - secrets, err := client.SecretList(ctx, types.SecretListOptions{}) + secrets, err := client.SecretList(ctx, types.SecretListOptions{Filters: opts.filter.Value()}) if err != nil { return err } diff --git a/command/service/parse.go b/command/service/parse.go index baf5e24547..77dfb25fbc 100644 --- a/command/service/parse.go +++ b/command/service/parse.go @@ -27,7 +27,7 @@ func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes. args := filters.NewArgs() for _, s := range secretRefs { - args.Add("names", s.SecretName) + args.Add("name", s.SecretName) } secrets, err := client.SecretList(ctx, types.SecretListOptions{