github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/v3_set_droplet_command.go (about) 1 package v6 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v3action" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/flag" 9 "code.cloudfoundry.org/cli/command/v6/shared" 10 ) 11 12 //go:generate counterfeiter . V3SetDropletActor 13 14 type V3SetDropletActor interface { 15 CloudControllerAPIVersion() string 16 SetApplicationDropletByApplicationNameAndSpace(appName string, spaceGUID string, dropletGUID string) (v3action.Warnings, error) 17 } 18 19 type V3SetDropletCommand struct { 20 RequiredArgs flag.AppName `positional-args:"yes"` 21 usage interface{} `usage:"CF_NAME v3-set-droplet APP_NAME -d DROPLET_GUID"` 22 DropletGUID string `short:"d" long:"droplet-guid" description:"The guid of the droplet to use" required:"true"` 23 24 UI command.UI 25 Config command.Config 26 SharedActor command.SharedActor 27 Actor V3SetDropletActor 28 } 29 30 func (cmd *V3SetDropletCommand) Setup(config command.Config, ui command.UI) error { 31 cmd.UI = ui 32 cmd.Config = config 33 cmd.SharedActor = sharedaction.NewActor(config) 34 35 ccClient, _, err := shared.NewV3BasedClients(config, ui, true, "") 36 if err != nil { 37 return err 38 } 39 cmd.Actor = v3action.NewActor(ccClient, config, nil, nil) 40 41 return nil 42 } 43 44 func (cmd V3SetDropletCommand) Execute(args []string) error { 45 cmd.UI.DisplayWarning(command.ExperimentalWarning) 46 47 err := command.MinimumCCAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionApplicationFlowV3) 48 if err != nil { 49 return err 50 } 51 52 err = cmd.SharedActor.CheckTarget(true, true) 53 if err != nil { 54 return err 55 } 56 57 user, err := cmd.Config.CurrentUser() 58 if err != nil { 59 return err 60 } 61 62 cmd.UI.DisplayTextWithFlavor("Setting app {{.AppName}} to droplet {{.DropletGUID}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 63 "AppName": cmd.RequiredArgs.AppName, 64 "DropletGUID": cmd.DropletGUID, 65 "OrgName": cmd.Config.TargetedOrganization().Name, 66 "SpaceName": cmd.Config.TargetedSpace().Name, 67 "Username": user.Name, 68 }) 69 70 warnings, err := cmd.Actor.SetApplicationDropletByApplicationNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID, cmd.DropletGUID) 71 cmd.UI.DisplayWarnings(warnings) 72 if err != nil { 73 return err 74 } 75 cmd.UI.DisplayOK() 76 77 return nil 78 }