From cb321e82db662f5190a6d83a90677a9dd9fdcd31 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Fri, 17 Jun 2016 18:13:24 +0200 Subject: [PATCH] Update plugin command with defaulttag This way, you don't have to specify the ":latest" tag for some command and not for others Signed-off-by: Vincent Demeester --- api/client/plugin/disable.go | 20 +++++++++++++++++++- api/client/plugin/enable.go | 20 +++++++++++++++++++- api/client/plugin/inspect.go | 15 ++++++++++++++- api/client/plugin/install.go | 4 +++- api/client/plugin/push.go | 4 +++- api/client/plugin/remove.go | 14 +++++++++++++- api/client/plugin/set.go | 16 +++++++++++++++- plugin/manager.go | 10 ++++++++++ 8 files changed, 96 insertions(+), 7 deletions(-) diff --git a/api/client/plugin/disable.go b/api/client/plugin/disable.go index 0382db24d2..058c6889cd 100644 --- a/api/client/plugin/disable.go +++ b/api/client/plugin/disable.go @@ -3,8 +3,11 @@ package plugin import ( + "fmt" + "github.com/docker/docker/api/client" "github.com/docker/docker/cli" + "github.com/docker/docker/reference" "github.com/spf13/cobra" "golang.org/x/net/context" ) @@ -15,9 +18,24 @@ func newDisableCommand(dockerCli *client.DockerCli) *cobra.Command { Short: "Disable a plugin", Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - return dockerCli.Client().PluginDisable(context.Background(), args[0]) + return runDisable(dockerCli, args[0]) }, } return cmd } + +func runDisable(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()) + } + return dockerCli.Client().PluginDisable(context.Background(), ref.String()) +} diff --git a/api/client/plugin/enable.go b/api/client/plugin/enable.go index 703ad37d19..cc2488bcec 100644 --- a/api/client/plugin/enable.go +++ b/api/client/plugin/enable.go @@ -3,8 +3,11 @@ package plugin import ( + "fmt" + "github.com/docker/docker/api/client" "github.com/docker/docker/cli" + "github.com/docker/docker/reference" "github.com/spf13/cobra" "golang.org/x/net/context" ) @@ -15,9 +18,24 @@ func newEnableCommand(dockerCli *client.DockerCli) *cobra.Command { Short: "Enable a plugin", Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - return dockerCli.Client().PluginEnable(context.Background(), args[0]) + return runEnable(dockerCli, args[0]) }, } return cmd } + +func runEnable(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()) + } + return dockerCli.Client().PluginEnable(context.Background(), ref.String()) +} diff --git a/api/client/plugin/inspect.go b/api/client/plugin/inspect.go index a091df4756..8f7e98d441 100644 --- a/api/client/plugin/inspect.go +++ b/api/client/plugin/inspect.go @@ -4,9 +4,11 @@ package plugin import ( "encoding/json" + "fmt" "github.com/docker/docker/api/client" "github.com/docker/docker/cli" + "github.com/docker/docker/reference" "github.com/spf13/cobra" "golang.org/x/net/context" ) @@ -25,7 +27,18 @@ func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command { } func runInspect(dockerCli *client.DockerCli, name string) error { - p, err := dockerCli.Client().PluginInspect(context.Background(), name) + 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 } diff --git a/api/client/plugin/install.go b/api/client/plugin/install.go index 2841388884..ea73498c26 100644 --- a/api/client/plugin/install.go +++ b/api/client/plugin/install.go @@ -46,7 +46,9 @@ func runInstall(dockerCli *client.DockerCli, opts pluginOptions) error { if err != nil { return err } - named = reference.WithDefaultTag(named) + if reference.IsNameOnly(named) { + named = reference.WithDefaultTag(named) + } ref, ok := named.(reference.NamedTagged) if !ok { return fmt.Errorf("invalid name: %s", named.String()) diff --git a/api/client/plugin/push.go b/api/client/plugin/push.go index e34b9679e9..d26fab8dfc 100644 --- a/api/client/plugin/push.go +++ b/api/client/plugin/push.go @@ -31,7 +31,9 @@ func runPush(dockerCli *client.DockerCli, name string) error { if err != nil { return err } - named = reference.WithDefaultTag(named) + if reference.IsNameOnly(named) { + named = reference.WithDefaultTag(named) + } ref, ok := named.(reference.NamedTagged) if !ok { return fmt.Errorf("invalid name: %s", named.String()) diff --git a/api/client/plugin/remove.go b/api/client/plugin/remove.go index 54c904a18a..a8e52a4f26 100644 --- a/api/client/plugin/remove.go +++ b/api/client/plugin/remove.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/api/client" "github.com/docker/docker/cli" + "github.com/docker/docker/reference" "github.com/spf13/cobra" "golang.org/x/net/context" ) @@ -28,8 +29,19 @@ func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command { func runRemove(dockerCli *client.DockerCli, names []string) error { var errs cli.Errors for _, name := range names { + 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()) + } // TODO: pass names to api instead of making multiple api calls - if err := dockerCli.Client().PluginRemove(context.Background(), name); err != nil { + if err := dockerCli.Client().PluginRemove(context.Background(), ref.String()); err != nil { errs = append(errs, err) continue } diff --git a/api/client/plugin/set.go b/api/client/plugin/set.go index 017f2b5325..188bd63cc4 100644 --- a/api/client/plugin/set.go +++ b/api/client/plugin/set.go @@ -3,10 +3,13 @@ package plugin import ( + "fmt" + "golang.org/x/net/context" "github.com/docker/docker/api/client" "github.com/docker/docker/cli" + "github.com/docker/docker/reference" "github.com/spf13/cobra" ) @@ -24,5 +27,16 @@ func newSetCommand(dockerCli *client.DockerCli) *cobra.Command { } func runSet(dockerCli *client.DockerCli, name string, args []string) error { - return dockerCli.Client().PluginSet(context.Background(), name, args) + 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()) + } + return dockerCli.Client().PluginSet(context.Background(), ref.String(), args) } diff --git a/plugin/manager.go b/plugin/manager.go index 006905764f..885e92e2c4 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -204,6 +204,16 @@ func LookupWithCapability(name, capability string) (Plugin, error) { ) handleLegacy := true if manager != nil { + if named, err := reference.ParseNamed(name); err == nil { // FIXME: validate + if reference.IsNameOnly(named) { + named = reference.WithDefaultTag(named) + } + ref, ok := named.(reference.NamedTagged) + if !ok { + return nil, fmt.Errorf("invalid name: %s", named.String()) + } + name = ref.String() + } p, err = manager.get(name) if err != nil { if _, ok := err.(ErrNotFound); !ok {