mirror of https://github.com/docker/cli.git
Merge pull request #30810 from allencloud/make-secret-ls-support-filter
make secret ls support filters in CLI
This commit is contained in:
commit
d14a4d4231
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/cli/command"
|
"github.com/docker/docker/cli/command"
|
||||||
"github.com/docker/docker/cli/command/formatter"
|
"github.com/docker/docker/cli/command/formatter"
|
||||||
|
"github.com/docker/docker/opts"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -12,10 +13,11 @@ import (
|
||||||
type listOptions struct {
|
type listOptions struct {
|
||||||
quiet bool
|
quiet bool
|
||||||
format string
|
format string
|
||||||
|
filter opts.FilterOpt
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
opts := listOptions{}
|
opts := listOptions{filter: opts.NewFilterOpt()}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "ls [OPTIONS]",
|
Use: "ls [OPTIONS]",
|
||||||
|
@ -30,6 +32,7 @@ func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
|
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
|
||||||
flags.StringVarP(&opts.format, "format", "", "", "Pretty-print secrets using a Go template")
|
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
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -38,7 +41,7 @@ func runSecretList(dockerCli *command.DockerCli, opts listOptions) error {
|
||||||
client := dockerCli.Client()
|
client := dockerCli.Client()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
secrets, err := client.SecretList(ctx, types.SecretListOptions{})
|
secrets, err := client.SecretList(ctx, types.SecretListOptions{Filters: opts.filter.Value()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.
|
||||||
|
|
||||||
args := filters.NewArgs()
|
args := filters.NewArgs()
|
||||||
for _, s := range secretRefs {
|
for _, s := range secretRefs {
|
||||||
args.Add("names", s.SecretName)
|
args.Add("name", s.SecretName)
|
||||||
}
|
}
|
||||||
|
|
||||||
secrets, err := client.SecretList(ctx, types.SecretListOptions{
|
secrets, err := client.SecretList(ctx, types.SecretListOptions{
|
||||||
|
|
Loading…
Reference in New Issue