forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.go
41 lines (32 loc) · 857 Bytes
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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] IMAGE[: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)
}