github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/commands/buildpack_pull.go (about) 1 package commands 2 3 import ( 4 "github.com/spf13/cobra" 5 6 "github.com/buildpacks/pack/internal/config" 7 "github.com/buildpacks/pack/internal/style" 8 "github.com/buildpacks/pack/pkg/client" 9 "github.com/buildpacks/pack/pkg/logging" 10 ) 11 12 // BuildpackPullFlags consist of flags applicable to the `buildpack pull` command 13 type BuildpackPullFlags struct { 14 // BuildpackRegistry is the name of the buildpack registry to use to search for 15 BuildpackRegistry string 16 } 17 18 // BuildpackPull pulls a buildpack and stores it locally 19 func BuildpackPull(logger logging.Logger, cfg config.Config, pack PackClient) *cobra.Command { 20 var flags BuildpackPullFlags 21 22 cmd := &cobra.Command{ 23 Use: "pull <uri>", 24 Args: cobra.ExactArgs(1), 25 Short: "Pull a buildpack from a registry and store it locally", 26 Example: "pack buildpack pull example/my-buildpack@1.0.0", 27 RunE: logError(logger, func(cmd *cobra.Command, args []string) error { 28 registry, err := config.GetRegistry(cfg, flags.BuildpackRegistry) 29 if err != nil { 30 return err 31 } 32 33 opts := client.PullBuildpackOptions{ 34 URI: args[0], 35 RegistryName: registry.Name, 36 } 37 38 if err := pack.PullBuildpack(cmd.Context(), opts); err != nil { 39 return err 40 } 41 logger.Infof("Successfully pulled %s", style.Symbol(opts.URI)) 42 return nil 43 }), 44 } 45 cmd.Flags().StringVarP(&flags.BuildpackRegistry, "buildpack-registry", "r", "", "Buildpack Registry name") 46 AddHelpFlag(cmd, "pull") 47 return cmd 48 }