inspect.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package secret
  2. import (
  3. "github.com/docker/docker/cli"
  4. "github.com/docker/docker/cli/command"
  5. "github.com/docker/docker/cli/command/inspect"
  6. "github.com/spf13/cobra"
  7. "golang.org/x/net/context"
  8. )
  9. type inspectOptions struct {
  10. names []string
  11. format string
  12. }
  13. func newSecretInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
  14. opts := inspectOptions{}
  15. cmd := &cobra.Command{
  16. Use: "inspect [OPTIONS] SECRET [SECRET...]",
  17. Short: "Display detailed information on one or more secrets",
  18. Args: cli.RequiresMinArgs(1),
  19. RunE: func(cmd *cobra.Command, args []string) error {
  20. opts.names = args
  21. return runSecretInspect(dockerCli, opts)
  22. },
  23. }
  24. cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
  25. return cmd
  26. }
  27. func runSecretInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
  28. client := dockerCli.Client()
  29. ctx := context.Background()
  30. getRef := func(id string) (interface{}, []byte, error) {
  31. return client.SecretInspectWithRaw(ctx, id)
  32. }
  33. return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getRef)
  34. }