inspect.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package plugin
  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. pluginNames []string
  11. format string
  12. }
  13. func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
  14. var opts inspectOptions
  15. cmd := &cobra.Command{
  16. Use: "inspect [OPTIONS] PLUGIN|ID [PLUGIN|ID...]",
  17. Short: "Display detailed information on one or more plugins",
  18. Args: cli.RequiresMinArgs(1),
  19. RunE: func(cmd *cobra.Command, args []string) error {
  20. opts.pluginNames = args
  21. return runInspect(dockerCli, opts)
  22. },
  23. }
  24. flags := cmd.Flags()
  25. flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
  26. return cmd
  27. }
  28. func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
  29. client := dockerCli.Client()
  30. ctx := context.Background()
  31. getRef := func(ref string) (interface{}, []byte, error) {
  32. return client.PluginInspectWithRaw(ctx, ref)
  33. }
  34. return inspect.Inspect(dockerCli.Out(), opts.pluginNames, opts.format, getRef)
  35. }