2016-05-16 15:50:55 +00:00
|
|
|
// +build experimental
|
|
|
|
|
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2016-06-17 16:13:24 +00:00
|
|
|
"fmt"
|
2016-05-16 15:50:55 +00:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/client"
|
2016-08-17 11:52:27 +00:00
|
|
|
"github.com/docker/docker/api/client/inspect"
|
2016-05-16 15:50:55 +00:00
|
|
|
"github.com/docker/docker/cli"
|
2016-06-17 16:13:24 +00:00
|
|
|
"github.com/docker/docker/reference"
|
2016-05-16 15:50:55 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-08-17 11:52:27 +00:00
|
|
|
type inspectOptions struct {
|
|
|
|
pluginNames []string
|
|
|
|
format string
|
|
|
|
}
|
|
|
|
|
2016-05-16 15:50:55 +00:00
|
|
|
func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
|
2016-08-17 11:52:27 +00:00
|
|
|
var opts inspectOptions
|
|
|
|
|
2016-05-16 15:50:55 +00:00
|
|
|
cmd := &cobra.Command{
|
2016-06-17 16:14:23 +00:00
|
|
|
Use: "inspect PLUGIN",
|
2016-05-16 15:50:55 +00:00
|
|
|
Short: "Inspect a plugin",
|
2016-08-17 11:52:27 +00:00
|
|
|
Args: cli.RequiresMinArgs(1),
|
2016-05-16 15:50:55 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2016-08-17 11:52:27 +00:00
|
|
|
opts.pluginNames = args
|
|
|
|
return runInspect(dockerCli, opts)
|
2016-05-16 15:50:55 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:52:27 +00:00
|
|
|
flags := cmd.Flags()
|
|
|
|
flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
|
2016-05-16 15:50:55 +00:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:52:27 +00:00
|
|
|
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
|
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
getRef := func(name string) (interface{}, []byte, error) {
|
|
|
|
named, err := reference.ParseNamed(name) // FIXME: validate
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
if reference.IsNameOnly(named) {
|
|
|
|
named = reference.WithDefaultTag(named)
|
|
|
|
}
|
|
|
|
ref, ok := named.(reference.NamedTagged)
|
|
|
|
if !ok {
|
|
|
|
return nil, nil, fmt.Errorf("invalid name: %s", named.String())
|
|
|
|
}
|
2016-05-16 15:50:55 +00:00
|
|
|
|
2016-08-17 11:52:27 +00:00
|
|
|
return client.PluginInspectWithRaw(ctx, ref.String())
|
2016-05-16 15:50:55 +00:00
|
|
|
}
|
2016-08-17 11:52:27 +00:00
|
|
|
|
|
|
|
return inspect.Inspect(dockerCli.Out(), opts.pluginNames, opts.format, getRef)
|
2016-05-16 15:50:55 +00:00
|
|
|
}
|