|
@@ -3,50 +3,57 @@
|
|
package plugin
|
|
package plugin
|
|
|
|
|
|
import (
|
|
import (
|
|
- "encoding/json"
|
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
|
"github.com/docker/docker/api/client"
|
|
"github.com/docker/docker/api/client"
|
|
|
|
+ "github.com/docker/docker/api/client/inspect"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/reference"
|
|
"github.com/docker/docker/reference"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/context"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+type inspectOptions struct {
|
|
|
|
+ pluginNames []string
|
|
|
|
+ format string
|
|
|
|
+}
|
|
|
|
+
|
|
func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
|
|
+ var opts inspectOptions
|
|
|
|
+
|
|
cmd := &cobra.Command{
|
|
cmd := &cobra.Command{
|
|
Use: "inspect PLUGIN",
|
|
Use: "inspect PLUGIN",
|
|
Short: "Inspect a plugin",
|
|
Short: "Inspect a plugin",
|
|
- Args: cli.ExactArgs(1),
|
|
|
|
|
|
+ Args: cli.RequiresMinArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
- return runInspect(dockerCli, args[0])
|
|
|
|
|
|
+ opts.pluginNames = args
|
|
|
|
+ return runInspect(dockerCli, opts)
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ flags := cmd.Flags()
|
|
|
|
+ flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
|
|
return cmd
|
|
return cmd
|
|
}
|
|
}
|
|
|
|
|
|
-func runInspect(dockerCli *client.DockerCli, name string) error {
|
|
|
|
- named, err := reference.ParseNamed(name) // FIXME: validate
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- if reference.IsNameOnly(named) {
|
|
|
|
- named = reference.WithDefaultTag(named)
|
|
|
|
- }
|
|
|
|
- ref, ok := named.(reference.NamedTagged)
|
|
|
|
- if !ok {
|
|
|
|
- return fmt.Errorf("invalid name: %s", named.String())
|
|
|
|
- }
|
|
|
|
- p, err := dockerCli.Client().PluginInspect(context.Background(), ref.String())
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
|
|
+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())
|
|
|
|
+ }
|
|
|
|
|
|
- b, err := json.MarshalIndent(p, "", "\t")
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
|
|
+ return client.PluginInspectWithRaw(ctx, ref.String())
|
|
}
|
|
}
|
|
- _, err = dockerCli.Out().Write(b)
|
|
|
|
- return err
|
|
|
|
|
|
+
|
|
|
|
+ return inspect.Inspect(dockerCli.Out(), opts.pluginNames, opts.format, getRef)
|
|
}
|
|
}
|