mirror of https://github.com/docker/docs.git
Merge pull request #23278 from yongtang/23211-spf13-cobra-tag
Use spf13/cobra for docker tag
This commit is contained in:
commit
55a8bfa0e8
|
|
@ -20,7 +20,6 @@ func (cli *DockerCli) Command(name string) func(...string) error {
|
||||||
"rm": cli.CmdRm,
|
"rm": cli.CmdRm,
|
||||||
"save": cli.CmdSave,
|
"save": cli.CmdSave,
|
||||||
"stats": cli.CmdStats,
|
"stats": cli.CmdStats,
|
||||||
"tag": cli.CmdTag,
|
|
||||||
"update": cli.CmdUpdate,
|
"update": cli.CmdUpdate,
|
||||||
"version": cli.CmdVersion,
|
"version": cli.CmdVersion,
|
||||||
}[name]
|
}[name]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/client"
|
||||||
|
"github.com/docker/docker/cli"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
type tagOptions struct {
|
||||||
|
image string
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTagCommand create a new `docker tag` command
|
||||||
|
func NewTagCommand(dockerCli *client.DockerCli) *cobra.Command {
|
||||||
|
var opts tagOptions
|
||||||
|
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]",
|
||||||
|
Short: "Tag an image into a repository",
|
||||||
|
Args: cli.ExactArgs(2),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
opts.image = args[0]
|
||||||
|
opts.name = args[1]
|
||||||
|
return runTag(dockerCli, opts)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
flags := cmd.Flags()
|
||||||
|
flags.SetInterspersed(false)
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func runTag(dockerCli *client.DockerCli, opts tagOptions) error {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
return dockerCli.Client().ImageTag(ctx, opts.image, opts.name)
|
||||||
|
}
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
package client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
Cli "github.com/docker/docker/cli"
|
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CmdTag tags an image into a repository.
|
|
||||||
//
|
|
||||||
// Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
|
|
||||||
func (cli *DockerCli) CmdTag(args ...string) error {
|
|
||||||
cmd := Cli.Subcmd("tag", []string{"IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]"}, Cli.DockerCommands["tag"].Description, true)
|
|
||||||
cmd.Require(flag.Exact, 2)
|
|
||||||
|
|
||||||
cmd.ParseFlags(args, true)
|
|
||||||
|
|
||||||
return cli.client.ImageTag(context.Background(), cmd.Arg(0), cmd.Arg(1))
|
|
||||||
}
|
|
||||||
|
|
@ -54,6 +54,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
|
||||||
image.NewRemoveCommand(dockerCli),
|
image.NewRemoveCommand(dockerCli),
|
||||||
image.NewSearchCommand(dockerCli),
|
image.NewSearchCommand(dockerCli),
|
||||||
image.NewImportCommand(dockerCli),
|
image.NewImportCommand(dockerCli),
|
||||||
|
image.NewTagCommand(dockerCli),
|
||||||
network.NewNetworkCommand(dockerCli),
|
network.NewNetworkCommand(dockerCli),
|
||||||
volume.NewVolumeCommand(dockerCli),
|
volume.NewVolumeCommand(dockerCli),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ var DockerCommandUsage = []Command{
|
||||||
{"rm", "Remove one or more containers"},
|
{"rm", "Remove one or more containers"},
|
||||||
{"save", "Save one or more images to a tar archive"},
|
{"save", "Save one or more images to a tar archive"},
|
||||||
{"stats", "Display a live stream of container(s) resource usage statistics"},
|
{"stats", "Display a live stream of container(s) resource usage statistics"},
|
||||||
{"tag", "Tag an image into a repository"},
|
|
||||||
{"update", "Update configuration of one or more containers"},
|
{"update", "Update configuration of one or more containers"},
|
||||||
{"version", "Show the Docker version information"},
|
{"version", "Show the Docker version information"},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue