github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/cli/command/plugin/inspect.go (about)

     1  package plugin
     2  
     3  import (
     4  	"fmt"
     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/docker/docker/reference"
    10  	"github.com/spf13/cobra"
    11  	"golang.org/x/net/context"
    12  )
    13  
    14  type inspectOptions struct {
    15  	pluginNames []string
    16  	format      string
    17  }
    18  
    19  func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
    20  	var opts inspectOptions
    21  
    22  	cmd := &cobra.Command{
    23  		Use:   "inspect [OPTIONS] PLUGIN [PLUGIN...]",
    24  		Short: "Display detailed information on one or more plugins",
    25  		Args:  cli.RequiresMinArgs(1),
    26  		RunE: func(cmd *cobra.Command, args []string) error {
    27  			opts.pluginNames = args
    28  			return runInspect(dockerCli, opts)
    29  		},
    30  	}
    31  
    32  	flags := cmd.Flags()
    33  	flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
    34  	return cmd
    35  }
    36  
    37  func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
    38  	client := dockerCli.Client()
    39  	ctx := context.Background()
    40  	getRef := func(name string) (interface{}, []byte, error) {
    41  		named, err := reference.ParseNamed(name) // FIXME: validate
    42  		if err != nil {
    43  			return nil, nil, err
    44  		}
    45  		if reference.IsNameOnly(named) {
    46  			named = reference.WithDefaultTag(named)
    47  		}
    48  		ref, ok := named.(reference.NamedTagged)
    49  		if !ok {
    50  			return nil, nil, fmt.Errorf("invalid name: %s", named.String())
    51  		}
    52  
    53  		return client.PluginInspectWithRaw(ctx, ref.String())
    54  	}
    55  
    56  	return inspect.Inspect(dockerCli.Out(), opts.pluginNames, opts.format, getRef)
    57  }