forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_inspect.go
65 lines (54 loc) · 1.77 KB
/
image_inspect.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"os"
"github.com/alibaba/pouch/cli/inspect"
"github.com/spf13/cobra"
)
// imageInspectDescription is used to describe inspect command in detail and auto generate command doc.
var imageInspectDescription = "Return detailed information on Pouch image"
// ImageInspectCommand use to implement 'image inspect' command.
type ImageInspectCommand struct {
baseCommand
format string
}
// Init initialize "image inspect" command.
func (i *ImageInspectCommand) Init(c *Cli) {
i.cli = c
i.cmd = &cobra.Command{
Use: "inspect [OPTIONS] IMAGE [IMAGE...]",
Short: "Display detailed information on one or more images",
Long: imageInspectDescription,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return i.runInspect(args)
},
Example: i.example(),
}
i.addFlags()
}
// addFlags adds flags for specific command.
func (i *ImageInspectCommand) addFlags() {
i.cmd.Flags().StringVarP(&i.format, "format", "f", "", "Format the output using the given go template")
}
// runInpsect is used to inspect image.
func (i *ImageInspectCommand) runInspect(args []string) error {
ctx := context.Background()
apiClient := i.cli.Client()
getRefFunc := func(ref string) (interface{}, error) {
return apiClient.ImageInspect(ctx, ref)
}
return inspect.Inspect(os.Stdout, args, i.format, getRefFunc)
}
// example shows examples in inspect command, and is used in auto-generated cli docs.
func (i *ImageInspectCommand) example() string {
return `$ pouch image inspect docker.io/library/busybox
{
"CreatedAt": "2017-12-21 04:30:57",
"Digest": "sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0",
"ID": "bbc3a0323522",
"Name": "docker.io/library/busybox:latest",
"Size": 720019,
"Tag": "latest"
}`
}