2016-04-19 12:59:48 -04:00
|
|
|
package volume
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cli"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/cli/command"
|
|
|
|
"github.com/docker/docker/cli/command/inspect"
|
2016-04-19 12:59:48 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type inspectOptions struct {
|
|
|
|
format string
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-04-19 12:59:48 -04:00
|
|
|
var opts inspectOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "inspect [OPTIONS] VOLUME [VOLUME...]",
|
2016-06-30 08:13:28 -04:00
|
|
|
Short: "Display detailed information on one or more volumes",
|
2016-06-20 16:33:53 -04:00
|
|
|
Long: inspectDescription,
|
2016-05-26 17:57:31 -04:00
|
|
|
Args: cli.RequiresMinArgs(1),
|
2016-04-19 12:59:48 -04:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
opts.names = args
|
|
|
|
return runInspect(dockerCli, opts)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
|
2016-04-19 12:59:48 -04:00
|
|
|
client := dockerCli.Client()
|
|
|
|
|
2016-06-09 11:58:10 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2016-04-19 12:59:48 -04:00
|
|
|
getVolFunc := func(name string) (interface{}, []byte, error) {
|
2016-06-09 11:58:10 -04:00
|
|
|
i, err := client.VolumeInspect(ctx, name)
|
2016-04-19 12:59:48 -04:00
|
|
|
return i, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getVolFunc)
|
|
|
|
}
|
2016-06-20 16:33:53 -04:00
|
|
|
|
|
|
|
var inspectDescription = `
|
|
|
|
Returns information about one or more volumes. By default, this command renders
|
|
|
|
all results in a JSON array. You can specify an alternate format to execute a
|
2016-06-22 10:12:18 -04:00
|
|
|
given template is executed for each result. Go's https://golang.org/pkg/text/template/
|
2016-06-20 16:33:53 -04:00
|
|
|
package describes all the details of the format.
|
|
|
|
|
|
|
|
`
|