github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/v3_apply_manifest_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/command" 7 "code.cloudfoundry.org/cli/command/flag" 8 "code.cloudfoundry.org/cli/command/v6/shared" 9 "code.cloudfoundry.org/cli/util/v6manifestparser" 10 "github.com/cloudfoundry/bosh-cli/director/template" 11 ) 12 13 //go:generate counterfeiter . ManifestParser 14 15 type ManifestParser interface { 16 v3action.ManifestParser 17 InterpolateAndParse(pathToManifest string, pathsToVarsFiles []string, vars []template.VarKV, appName string) error 18 } 19 20 //go:generate counterfeiter . V3ApplyManifestActor 21 22 type V3ApplyManifestActor interface { 23 ApplyApplicationManifest(parser v3action.ManifestParser, spaceGUID string) (v3action.Warnings, error) 24 } 25 26 type V3ApplyManifestCommand struct { 27 PathToManifest flag.PathWithExistenceCheck `short:"f" description:"Path to app manifest" required:"true"` 28 usage interface{} `usage:"CF_NAME v3-apply-manifest -f APP_MANIFEST_PATH"` 29 30 UI command.UI 31 Config command.Config 32 SharedActor command.SharedActor 33 Actor V3ApplyManifestActor 34 Parser ManifestParser 35 } 36 37 func (cmd *V3ApplyManifestCommand) Setup(config command.Config, ui command.UI) error { 38 cmd.UI = ui 39 cmd.Config = config 40 cmd.SharedActor = sharedaction.NewActor(config) 41 42 ccClient, _, err := shared.NewV3BasedClients(config, ui, true) 43 if err != nil { 44 return err 45 } 46 cmd.Actor = v3action.NewActor(ccClient, config, nil, nil) 47 cmd.Parser = v6manifestparser.NewParser() 48 49 return nil 50 } 51 52 func (cmd V3ApplyManifestCommand) Execute(args []string) error { 53 pathToManifest := string(cmd.PathToManifest) 54 55 cmd.UI.DisplayWarning(command.ExperimentalWarning) 56 57 err := cmd.SharedActor.CheckTarget(true, true) 58 if err != nil { 59 return err 60 } 61 62 user, err := cmd.Config.CurrentUser() 63 if err != nil { 64 return err 65 } 66 67 cmd.UI.DisplayTextWithFlavor("Applying manifest {{.ManifestPath}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 68 "ManifestPath": pathToManifest, 69 "OrgName": cmd.Config.TargetedOrganization().Name, 70 "SpaceName": cmd.Config.TargetedSpace().Name, 71 "Username": user.Name, 72 }) 73 74 err = cmd.Parser.InterpolateAndParse(pathToManifest, nil, nil, "") 75 if err != nil { 76 return err 77 } 78 79 warnings, err := cmd.Actor.ApplyApplicationManifest(cmd.Parser, cmd.Config.TargetedSpace().GUID) 80 cmd.UI.DisplayWarnings(warnings) 81 if err != nil { 82 return err 83 } 84 85 cmd.UI.DisplayOK() 86 87 return nil 88 }