mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <vincent@sbr.pm>
This commit is contained in:
parent
65ed9daf70
commit
cb321e82db
8 changed files with 96 additions and 7 deletions
|
@ -3,8 +3,11 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/api/client"
|
"github.com/docker/docker/api/client"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
|
"github.com/docker/docker/reference"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -15,9 +18,24 @@ func newDisableCommand(dockerCli *client.DockerCli) *cobra.Command {
|
||||||
Short: "Disable a plugin",
|
Short: "Disable a plugin",
|
||||||
Args: cli.ExactArgs(1),
|
Args: cli.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return dockerCli.Client().PluginDisable(context.Background(), args[0])
|
return runDisable(dockerCli, args[0])
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd
|
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())
|
||||||
|
}
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/api/client"
|
"github.com/docker/docker/api/client"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
|
"github.com/docker/docker/reference"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -15,9 +18,24 @@ func newEnableCommand(dockerCli *client.DockerCli) *cobra.Command {
|
||||||
Short: "Enable a plugin",
|
Short: "Enable a plugin",
|
||||||
Args: cli.ExactArgs(1),
|
Args: cli.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return dockerCli.Client().PluginEnable(context.Background(), args[0])
|
return runEnable(dockerCli, args[0])
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd
|
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())
|
||||||
|
}
|
||||||
|
|
|
@ -4,9 +4,11 @@ package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/api/client"
|
"github.com/docker/docker/api/client"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
|
"github.com/docker/docker/reference"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -25,7 +27,18 @@ func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runInspect(dockerCli *client.DockerCli, name string) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,9 @@ func runInstall(dockerCli *client.DockerCli, opts pluginOptions) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
named = reference.WithDefaultTag(named)
|
if reference.IsNameOnly(named) {
|
||||||
|
named = reference.WithDefaultTag(named)
|
||||||
|
}
|
||||||
ref, ok := named.(reference.NamedTagged)
|
ref, ok := named.(reference.NamedTagged)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("invalid name: %s", named.String())
|
return fmt.Errorf("invalid name: %s", named.String())
|
||||||
|
|
|
@ -31,7 +31,9 @@ func runPush(dockerCli *client.DockerCli, name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
named = reference.WithDefaultTag(named)
|
if reference.IsNameOnly(named) {
|
||||||
|
named = reference.WithDefaultTag(named)
|
||||||
|
}
|
||||||
ref, ok := named.(reference.NamedTagged)
|
ref, ok := named.(reference.NamedTagged)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("invalid name: %s", named.String())
|
return fmt.Errorf("invalid name: %s", named.String())
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/client"
|
"github.com/docker/docker/api/client"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
|
"github.com/docker/docker/reference"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -28,8 +29,19 @@ func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command {
|
||||||
func runRemove(dockerCli *client.DockerCli, names []string) error {
|
func runRemove(dockerCli *client.DockerCli, names []string) error {
|
||||||
var errs cli.Errors
|
var errs cli.Errors
|
||||||
for _, name := range names {
|
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
|
// 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)
|
errs = append(errs, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,13 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/docker/docker/api/client"
|
"github.com/docker/docker/api/client"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
|
"github.com/docker/docker/reference"
|
||||||
"github.com/spf13/cobra"
|
"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 {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,6 +204,16 @@ func LookupWithCapability(name, capability string) (Plugin, error) {
|
||||||
)
|
)
|
||||||
handleLegacy := true
|
handleLegacy := true
|
||||||
if manager != nil {
|
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)
|
p, err = manager.get(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(ErrNotFound); !ok {
|
if _, ok := err.(ErrNotFound); !ok {
|
||||||
|
|
Loading…
Reference in a new issue