github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/command/v2/create_app_manifest_command.go (about) 1 package v2 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/liamawhite/cli-with-i18n/actor/sharedaction" 8 "github.com/liamawhite/cli-with-i18n/actor/v2action" 9 "github.com/liamawhite/cli-with-i18n/command" 10 "github.com/liamawhite/cli-with-i18n/command/flag" 11 "github.com/liamawhite/cli-with-i18n/command/v2/shared" 12 ) 13 14 //go:generate counterfeiter . CreateAppManifestActor 15 16 type CreateAppManifestActor interface { 17 CreateApplicationManifestByNameAndSpace(appName string, spaceGUID string, filePath string) (v2action.Warnings, error) 18 } 19 20 type CreateAppManifestCommand struct { 21 RequiredArgs flag.AppName `positional-args:"yes"` 22 FilePath flag.Path `short:"p" description:"Specify a path for file creation. If path not specified, manifest file is created in current working directory."` 23 usage interface{} `usage:"CF_NAME create-app-manifest APP_NAME [-p /path/to/<app-name>_manifest.yml]"` 24 relatedCommands interface{} `related_commands:"apps, push"` 25 26 UI command.UI 27 Config command.Config 28 SharedActor command.SharedActor 29 Actor CreateAppManifestActor 30 } 31 32 func (cmd *CreateAppManifestCommand) Setup(config command.Config, ui command.UI) error { 33 cmd.UI = ui 34 cmd.Config = config 35 cmd.SharedActor = sharedaction.NewActor(config) 36 37 ccClient, uaaClient, err := shared.NewClients(config, ui, true) 38 if err != nil { 39 return err 40 } 41 cmd.Actor = v2action.NewActor(ccClient, uaaClient, config) 42 43 return nil 44 } 45 46 func (cmd CreateAppManifestCommand) Execute(args []string) error { 47 err := cmd.SharedActor.CheckTarget(cmd.Config, true, true) 48 if err != nil { 49 return shared.HandleError(err) 50 } 51 52 user, err := cmd.Config.CurrentUser() 53 if err != nil { 54 return shared.HandleError(err) 55 } 56 57 cmd.UI.DisplayTextWithFlavor("Creating an app manifest from current settings of app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 58 "AppName": cmd.RequiredArgs.AppName, 59 "OrgName": cmd.Config.TargetedOrganization().Name, 60 "SpaceName": cmd.Config.TargetedSpace().Name, 61 "Username": user.Name, 62 }) 63 64 manifestPath := cmd.FilePath.String() 65 if manifestPath == "" { 66 manifestPath = fmt.Sprintf(".%s%s_manifest.yml", string(os.PathSeparator), cmd.RequiredArgs.AppName) 67 } 68 warnings, err := cmd.Actor.CreateApplicationManifestByNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID, manifestPath) 69 70 cmd.UI.DisplayWarnings(warnings) 71 if err != nil { 72 return shared.HandleError(err) 73 } 74 75 cmd.UI.DisplayOK() 76 cmd.UI.DisplayText("Manifest file created successfully at {{.FilePath}}", map[string]interface{}{ 77 "FilePath": manifestPath, 78 }) 79 80 return nil 81 }