github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/volume/inspect.go (about)

     1  package volume
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/docker/cli/cli"
     7  	"github.com/docker/cli/cli/command"
     8  	"github.com/docker/cli/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.Cli) *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  		Args:  cli.RequiresMinArgs(1),
    24  		RunE: func(cmd *cobra.Command, args []string) error {
    25  			opts.names = args
    26  			return runInspect(dockerCli, opts)
    27  		},
    28  	}
    29  
    30  	cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
    31  
    32  	return cmd
    33  }
    34  
    35  func runInspect(dockerCli command.Cli, opts inspectOptions) error {
    36  	client := dockerCli.Client()
    37  
    38  	ctx := context.Background()
    39  
    40  	getVolFunc := func(name string) (interface{}, []byte, error) {
    41  		i, err := client.VolumeInspect(ctx, name)
    42  		return i, nil, err
    43  	}
    44  
    45  	return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getVolFunc)
    46  }