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