summaryrefslogtreecommitdiff
path: root/cmd/podman/volume_inspect.go
blob: a8e6f489fc2b4a6f47c86283b60610217635bc22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main

import (
	"github.com/containers/libpod/cmd/podman/cliconfig"
	"github.com/containers/libpod/cmd/podman/libpodruntime"
	"github.com/pkg/errors"
	"github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)

var (
	volumeInspectCommand     cliconfig.VolumeInspectValues
	volumeInspectDescription = `
podman volume inspect

Display detailed information on one or more volumes. Can change the format
from JSON to a Go template.
`
	_volumeInspectCommand = &cobra.Command{
		Use:   "inspect",
		Short: "Display detailed information on one or more volumes",
		Long:  volumeInspectDescription,
		RunE: func(cmd *cobra.Command, args []string) error {
			volumeInspectCommand.InputArgs = args
			volumeInspectCommand.GlobalFlags = MainGlobalOpts
			return volumeInspectCmd(&volumeInspectCommand)
		},
		Example: "[VOLUME-NAME ...]",
	}
)

func init() {
	volumeInspectCommand.Command = _volumeInspectCommand
	volumeInspectCommand.SetUsageTemplate(UsageTemplate())
	flags := volumeInspectCommand.Flags()
	flags.BoolVarP(&volumeInspectCommand.All, "all", "a", false, "Inspect all volumes")
	flags.StringVarP(&volumeInspectCommand.Format, "format", "f", "json", "Format volume output using Go template")

}

func volumeInspectCmd(c *cliconfig.VolumeInspectValues) error {
	var err error

	runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
	if err != nil {
		return errors.Wrapf(err, "error creating libpod runtime")
	}
	defer runtime.Shutdown(false)

	opts := volumeLsOptions{
		Format: c.Format,
	}

	vols, lastError := getVolumesFromContext(&c.PodmanCommand, runtime)
	if lastError != nil {
		logrus.Errorf("%q", lastError)
	}

	return generateVolLsOutput(vols, opts, runtime)
}