inspect.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package volume
  2. import (
  3. "golang.org/x/net/context"
  4. "github.com/docker/docker/api/client"
  5. "github.com/docker/docker/api/client/inspect"
  6. "github.com/docker/docker/cli"
  7. "github.com/spf13/cobra"
  8. )
  9. type inspectOptions struct {
  10. format string
  11. names []string
  12. }
  13. func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
  14. var opts inspectOptions
  15. cmd := &cobra.Command{
  16. Use: "inspect [OPTIONS] VOLUME [VOLUME...]",
  17. Short: "Display detailed information on one or more volumes",
  18. Long: inspectDescription,
  19. Args: cli.RequiresMinArgs(1),
  20. RunE: func(cmd *cobra.Command, args []string) error {
  21. opts.names = args
  22. return runInspect(dockerCli, opts)
  23. },
  24. }
  25. cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
  26. return cmd
  27. }
  28. func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
  29. client := dockerCli.Client()
  30. ctx := context.Background()
  31. getVolFunc := func(name string) (interface{}, []byte, error) {
  32. i, err := client.VolumeInspect(ctx, name)
  33. return i, nil, err
  34. }
  35. return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getVolFunc)
  36. }
  37. var inspectDescription = `
  38. Returns information about one or more volumes. By default, this command renders
  39. all results in a JSON array. You can specify an alternate format to execute a
  40. given template is executed for each result. Go's https://golang.org/pkg/text/template/
  41. package describes all the details of the format.
  42. `