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