github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/cmd/pull.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "github.com/sirupsen/logrus" 6 "github.com/solo-io/unik/pkg/client" 7 "github.com/spf13/cobra" 8 ) 9 10 // pushCmd represents the push command 11 var pullCmd = &cobra.Command{ 12 Use: "pull", 13 Short: "Pull an image from a Unik Image Repository", 14 Long: ` 15 Example usage: 16 unik pull --image theirImage --provider virtualbox|qemu|xen 17 18 Requires that you first authenticate to a unik image repository with 'unik login' 19 `, 20 Run: func(cmd *cobra.Command, args []string) { 21 if err := readClientConfig(); err != nil { 22 logrus.Fatal(err) 23 } 24 c, err := getHubConfig() 25 if err != nil { 26 logrus.Fatal(err) 27 } 28 if imageName == "" { 29 logrus.Fatal("--image must be set") 30 } 31 if provider == "" { 32 logrus.Fatal("--provider must be set") 33 } 34 if host == "" { 35 host = clientConfig.Host 36 } 37 if err := client.UnikClient(host).Images().Pull(c, imageName, provider, force); err != nil { 38 logrus.Fatal(err) 39 } 40 fmt.Println(imageName + " pulled") 41 }, 42 } 43 44 func init() { 45 RootCmd.AddCommand(pullCmd) 46 pullCmd.Flags().StringVar(&imageName, "image", "", "<string,required> image to pull") 47 pullCmd.Flags().StringVar(&provider, "provider", "", "<string,required> name of the provider the image is built for") 48 pullCmd.Flags().BoolVar(&force, "force", false, "<bool,optional> force overwriting local image of the same name") 49 }