github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/commands/application/restage.go (about) 1 package application 2 3 import ( 4 "github.com/cloudfoundry/cli/cf/api/applications" 5 "github.com/cloudfoundry/cli/cf/command_metadata" 6 "github.com/cloudfoundry/cli/cf/configuration/core_config" 7 "github.com/cloudfoundry/cli/cf/errors" 8 . "github.com/cloudfoundry/cli/cf/i18n" 9 "github.com/cloudfoundry/cli/cf/models" 10 "github.com/cloudfoundry/cli/cf/requirements" 11 "github.com/cloudfoundry/cli/cf/terminal" 12 "github.com/codegangsta/cli" 13 ) 14 15 type Restage struct { 16 ui terminal.UI 17 config core_config.Reader 18 appRepo applications.ApplicationRepository 19 appStagingWatcher ApplicationStagingWatcher 20 } 21 22 func NewRestage(ui terminal.UI, config core_config.Reader, appRepo applications.ApplicationRepository, stagingWatcher ApplicationStagingWatcher) *Restage { 23 cmd := new(Restage) 24 cmd.ui = ui 25 cmd.config = config 26 cmd.appRepo = appRepo 27 cmd.appStagingWatcher = stagingWatcher 28 return cmd 29 } 30 31 func (cmd *Restage) Metadata() command_metadata.CommandMetadata { 32 return command_metadata.CommandMetadata{ 33 Name: "restage", 34 ShortName: "rg", 35 Description: T("Restage an app"), 36 Usage: T("CF_NAME restage APP_NAME"), 37 } 38 } 39 40 func (cmd *Restage) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) { 41 if len(c.Args()) != 1 { 42 cmd.ui.FailWithUsage(c) 43 } 44 45 return []requirements.Requirement{requirementsFactory.NewLoginRequirement()}, nil 46 } 47 48 func (cmd *Restage) Run(c *cli.Context) { 49 app, err := cmd.appRepo.Read(c.Args()[0]) 50 if notFound, ok := err.(*errors.ModelNotFoundError); ok { 51 cmd.ui.Failed(notFound.Error()) 52 } 53 54 cmd.ui.Say(T("Restaging app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", 55 map[string]interface{}{ 56 "AppName": terminal.EntityNameColor(app.Name), 57 "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), 58 "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), 59 "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), 60 })) 61 62 cmd.appStagingWatcher.ApplicationWatchStaging(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name, func(app models.Application) (models.Application, error) { 63 return app, cmd.appRepo.CreateRestageRequest(app.Guid) 64 }) 65 }