forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.go
45 lines (37 loc) · 1.08 KB
/
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
42
43
44
45
package main
import (
"context"
"github.com/spf13/cobra"
)
// tagDescription
var tagDescription = "tag command is to add tag reference for the existing image."
// TagCommand use to implement 'tag' command.
type TagCommand struct {
baseCommand
args []string
}
// Init initialize tag command.
func (tag *TagCommand) Init(c *Cli) {
tag.cli = c
tag.cmd = &cobra.Command{
Use: "tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]",
Short: "Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE",
Long: tagDescription,
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
return tag.runTag(args)
},
Example: tagExamples(),
}
}
// runTag is the entry of tag command.
func (tag *TagCommand) runTag(args []string) error {
ctx := context.Background()
apiClient := tag.cli.Client()
source, target := args[0], args[1]
return apiClient.ImageTag(ctx, source, target)
}
// tagExamples shows examples in tag command, and is used in auto-generated cli docs.
func tagExamples() string {
return `$ pouch tag registry.hub.docker.com/library/busybox:1.28 busybox:latest`
}