/
pull.go
58 lines (47 loc) · 939 Bytes
/
pull.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
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
type pullOptions struct {
name string
globalOptions *globalOptions
}
func newPullCommand() *cobra.Command {
cmd := &cobra.Command{
Args: cobra.ExactArgs(1),
Short: "Pull an image",
Use: "pull [name]",
RunE: func(cmd *cobra.Command, args []string) error {
globalOptions, err := newGlobalOptions(cmd)
if err != nil {
return err
}
opts := &pullOptions{
name: args[0],
globalOptions: globalOptions,
}
if err := runPull(opts); err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
return nil
},
}
return cmd
}
func runPull(opts *pullOptions) error {
eng, err := newEngine(opts.globalOptions)
if err != nil {
return err
}
if err != nil {
return err
}
img := eng.FindImage(opts.name)
if img == nil {
return fmt.Errorf(`image "%s" not found`, opts.name)
}
return img.Pull()
}