inspect.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package plugin
  2. import (
  3. "fmt"
  4. "github.com/docker/docker/cli"
  5. "github.com/docker/docker/cli/command"
  6. "github.com/docker/docker/cli/command/inspect"
  7. "github.com/docker/docker/reference"
  8. "github.com/spf13/cobra"
  9. "golang.org/x/net/context"
  10. )
  11. type inspectOptions struct {
  12. pluginNames []string
  13. format string
  14. }
  15. func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
  16. var opts inspectOptions
  17. cmd := &cobra.Command{
  18. Use: "inspect [OPTIONS] PLUGIN [PLUGIN...]",
  19. Short: "Display detailed information on one or more plugins",
  20. Args: cli.RequiresMinArgs(1),
  21. RunE: func(cmd *cobra.Command, args []string) error {
  22. opts.pluginNames = args
  23. return runInspect(dockerCli, opts)
  24. },
  25. }
  26. flags := cmd.Flags()
  27. flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
  28. return cmd
  29. }
  30. func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
  31. client := dockerCli.Client()
  32. ctx := context.Background()
  33. getRef := func(name string) (interface{}, []byte, error) {
  34. named, err := reference.ParseNamed(name) // FIXME: validate
  35. if err != nil {
  36. return nil, nil, err
  37. }
  38. if reference.IsNameOnly(named) {
  39. named = reference.WithDefaultTag(named)
  40. }
  41. ref, ok := named.(reference.NamedTagged)
  42. if !ok {
  43. return nil, nil, fmt.Errorf("invalid name: %s", named.String())
  44. }
  45. return client.PluginInspectWithRaw(ctx, ref.String())
  46. }
  47. return inspect.Inspect(dockerCli.Out(), opts.pluginNames, opts.format, getRef)
  48. }