github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/create_package_command.go (about) 1 package v7 2 3 import ( 4 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/v7action" 5 "github.com/LukasHeimann/cloudfoundrycli/v8/command" 6 "github.com/LukasHeimann/cloudfoundrycli/v8/command/flag" 7 "github.com/LukasHeimann/cloudfoundrycli/v8/command/translatableerror" 8 "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7/shared" 9 "github.com/LukasHeimann/cloudfoundrycli/v8/resources" 10 ) 11 12 type CreatePackageCommand struct { 13 BaseCommand 14 15 RequiredArgs flag.AppName `positional-args:"yes"` 16 DockerImage flag.DockerImage `long:"docker-image" short:"o" description:"Docker image to use (e.g. user/docker-image-name)"` 17 AppPath flag.PathWithExistenceCheck `short:"p" description:"Path to app directory or to a zip file of the contents of the app directory"` 18 usage interface{} `usage:"CF_NAME create-package APP_NAME [-p APP_PATH | --docker-image [REGISTRY_HOST:PORT/]IMAGE[:TAG]]"` 19 relatedCommands interface{} `related_commands:"app, droplets, packages, push"` 20 21 PackageDisplayer shared.PackageDisplayer 22 } 23 24 func (cmd *CreatePackageCommand) Setup(config command.Config, ui command.UI) error { 25 cmd.PackageDisplayer = shared.NewPackageDisplayer(ui, config) 26 return cmd.BaseCommand.Setup(config, ui) 27 } 28 29 func (cmd CreatePackageCommand) Execute(args []string) error { 30 if cmd.DockerImage.Path != "" && cmd.AppPath != "" { 31 return translatableerror.ArgumentCombinationError{ 32 Args: []string{"--docker-image", "-o", "-p"}, 33 } 34 } 35 36 err := cmd.SharedActor.CheckTarget(true, true) 37 if err != nil { 38 return err 39 } 40 41 isDockerImage := (cmd.DockerImage.Path != "") 42 user, err := cmd.Actor.GetCurrentUser() 43 if err != nil { 44 return err 45 } 46 err = cmd.PackageDisplayer.DisplaySetupMessage(cmd.RequiredArgs.AppName, user.Name, isDockerImage) 47 if err != nil { 48 return err 49 } 50 51 var ( 52 pkg resources.Package 53 warnings v7action.Warnings 54 ) 55 if isDockerImage { 56 pkg, warnings, err = cmd.Actor.CreateDockerPackageByApplicationNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID, v7action.DockerImageCredentials{Path: cmd.DockerImage.Path}) 57 } else { 58 pkg, warnings, err = cmd.Actor.CreateAndUploadBitsPackageByApplicationNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID, string(cmd.AppPath)) 59 } 60 61 cmd.UI.DisplayWarnings(warnings) 62 if err != nil { 63 return err 64 } 65 66 cmd.UI.DisplayText("Package with guid '{{.PackageGuid}}' has been created.", map[string]interface{}{ 67 "PackageGuid": pkg.GUID, 68 }) 69 cmd.UI.DisplayOK() 70 71 return nil 72 }