github.com/olljanat/moby@v1.13.1/cli/command/volume/inspect.go (about)

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