func (cmd Login) authenticate(c *cli.Context) (apiResponse net.ApiResponse) { username := c.String("u") if username == "" { username = cmd.ui.Ask("Username%s", terminal.PromptColor(">")) } password := c.String("p") for i := 0; i < maxLoginTries; i++ { if password == "" || i > 0 { password = cmd.ui.AskForPassword("Password%s", terminal.PromptColor(">")) } cmd.ui.Say("Authenticating...") apiResponse = cmd.authenticator.Authenticate(username, password) if apiResponse.IsSuccessful() { cmd.ui.Ok() cmd.ui.Say("") break } cmd.ui.Say(apiResponse.Message) } return }
func (cmd Password) Run(c *cli.Context) { oldPassword := cmd.ui.AskForPassword("Current Password%s", term.PromptColor(">")) newPassword := cmd.ui.AskForPassword("New Password%s", term.PromptColor(">")) verifiedPassword := cmd.ui.AskForPassword("Verify Password%s", term.PromptColor(">")) if verifiedPassword != newPassword { cmd.ui.Failed("Password verification does not match") return } score, err := cmd.pwdRepo.GetScore(newPassword) if err != nil { cmd.ui.Failed(err.Error()) return } cmd.ui.Say("Your password strength is: %s", score) cmd.ui.Say("Changing password...") err = cmd.pwdRepo.UpdatePassword(oldPassword, newPassword) if err != nil { if err.StatusCode == 401 { cmd.ui.Failed("Current password did not match") } else { cmd.ui.Failed(err.Error()) } return } cmd.ui.Ok() cmd.configRepo.ClearSession() cmd.ui.Say("Please log back in.") }
func (cmd Password) Run(c *cli.Context) { oldPassword := cmd.ui.AskForPassword("Current Password%s", terminal.PromptColor(">")) newPassword := cmd.ui.AskForPassword("New Password%s", terminal.PromptColor(">")) verifiedPassword := cmd.ui.AskForPassword("Verify Password%s", terminal.PromptColor(">")) if verifiedPassword != newPassword { cmd.ui.Failed("Password verification does not match") return } score, apiResponse := cmd.pwdRepo.GetScore(newPassword) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Say("Your password strength is: %s", score) cmd.ui.Say("Changing password...") apiResponse = cmd.pwdRepo.UpdatePassword(oldPassword, newPassword) if apiResponse.IsNotSuccessful() { if apiResponse.StatusCode == 401 { cmd.ui.Failed("Current password did not match") } else { cmd.ui.Failed(apiResponse.Message) } return } cmd.ui.Ok() cmd.configRepo.ClearSession() cmd.ui.Say("Please log in again") }
func (cmd Password) Run(c *cli.Context) { oldPassword := cmd.ui.AskForPassword("Current Password%s", terminal.PromptColor(">")) newPassword := cmd.ui.AskForPassword("New Password%s", terminal.PromptColor(">")) verifiedPassword := cmd.ui.AskForPassword("Verify Password%s", terminal.PromptColor(">")) if verifiedPassword != newPassword { cmd.ui.Failed("Password verification does not match") return } cmd.ui.Say("Changing password...") apiErr := cmd.pwdRepo.UpdatePassword(oldPassword, newPassword) switch typedErr := apiErr.(type) { case nil: case errors.HttpError: if typedErr.StatusCode() == 401 { cmd.ui.Failed("Current password did not match") } else { cmd.ui.Failed(apiErr.Error()) } default: cmd.ui.Failed(apiErr.Error()) } cmd.ui.Ok() cmd.config.ClearSession() cmd.ui.Say("Please log in again") }
func (cmd CreateUserProvidedService) mapValuesFromPrompt(params string, paramsMap map[string]string) map[string]string { for _, param := range strings.Split(params, ",") { param = strings.Trim(param, " ") paramsMap[param] = cmd.ui.Ask("%s%s", param, terminal.PromptColor(">")) } return paramsMap }
func (cmd DeleteServiceAuthToken) Run(c *cli.Context) { tokenLabel := c.Args()[0] tokenProvider := c.Args()[1] if c.Bool("f") == false { response := cmd.ui.Confirm( "Are you sure you want to delete %s?%s", terminal.EntityNameColor(fmt.Sprintf("%s %s", tokenLabel, tokenProvider)), terminal.PromptColor(">"), ) if response == false { return } } cmd.ui.Say("Deleting service auth token as %s", terminal.EntityNameColor(cmd.config.Username())) token, apiResponse := cmd.authTokenRepo.FindByLabelAndProvider(tokenLabel, tokenProvider) if apiResponse.IsError() { cmd.ui.Failed(apiResponse.Message) return } if apiResponse.IsNotFound() { cmd.ui.Ok() cmd.ui.Warn("Service Auth Token %s %s does not exist.", tokenLabel, tokenProvider) return } apiResponse = cmd.authTokenRepo.Delete(token) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Ok() }
func (cmd *DeleteSpace) Run(c *cli.Context) { space := cmd.spaceReq.GetSpace() force := c.Bool("f") if !force { response := strings.ToLower(cmd.ui.Ask( "Really delete space %s and everything associated with it?%s", term.EntityNameColor(space.Name), term.PromptColor(">"), )) if response != "y" && response != "yes" { return } } cmd.ui.Say("Deleting space %s...", term.EntityNameColor(space.Name)) err := cmd.spaceRepo.Delete(space) if err != nil { cmd.ui.Failed(err.Error()) return } cmd.ui.Ok() return }
func (cmd DeleteUser) Run(c *cli.Context) { username := c.Args()[0] force := c.Bool("f") if !force && !cmd.ui.Confirm("Really delete user %s?%s", terminal.EntityNameColor(username), terminal.PromptColor(">"), ) { return } cmd.ui.Say("Deleting user %s as %s...", terminal.EntityNameColor(username), terminal.EntityNameColor(cmd.config.Username()), ) user, apiResponse := cmd.userRepo.FindByUsername(username) if apiResponse.IsError() { cmd.ui.Failed(apiResponse.Message) return } if apiResponse.IsNotFound() { cmd.ui.Ok() cmd.ui.Warn("User %s does not exist.", username) return } apiResponse = cmd.userRepo.Delete(user) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Ok() }
func (d *Delete) Run(c *cli.Context) { app := d.appReq.GetApplication() force := c.Bool("f") if !force { response := strings.ToLower(d.ui.Ask( "Really delete %s?%s", term.EntityNameColor(app.Name), term.PromptColor(">"), )) if response != "y" && response != "yes" { return } } d.ui.Say("Deleting app %s...", term.EntityNameColor(app.Name)) err := d.appRepo.Delete(app) if err != nil { d.ui.Failed(err.Error()) return } d.ui.Ok() return }
func (cmd Login) promptForName(names []string, listPrompt, itemPrompt string) string { nameIndex := 0 var nameString string for nameIndex < 1 || nameIndex > len(names) { var err error // list header cmd.ui.Say(listPrompt) // only display list if it is shorter than 50 if len(names) < 50 { for i, name := range names { cmd.ui.Say("%d. %s", i+1, name) } } nameString = cmd.ui.Ask("%s%s", itemPrompt, terminal.PromptColor(">")) nameIndex, err = strconv.Atoi(nameString) if err != nil { cmd.ui.Say("") nameIndex = 1 return nameString } } return names[nameIndex-1] }
func (cmd Login) promptForName(names []string, listPrompt, itemPrompt string) string { nameIndex := 0 var nameString string for nameIndex < 1 || nameIndex > len(names) { var err error // list header cmd.ui.Say(listPrompt) // only display list if it is shorter than maxChoices if len(names) < maxChoices { for i, name := range names { cmd.ui.Say("%d. %s", i+1, name) } } else { cmd.ui.Say("There are too many options to display, please type in the name.") } nameString = cmd.ui.Ask("%s%s", itemPrompt, terminal.PromptColor(">")) if nameString == "" { return "" } nameIndex, err = strconv.Atoi(nameString) if err != nil { nameIndex = 1 return nameString } } return names[nameIndex-1] }
func (ui *FakeUI) ConfirmDelete(modelType, modelName string) bool { return ui.Confirm( "Really delete the %s %s?%s", modelType, term.EntityNameColor(modelName), term.PromptColor(">")) }
func (cmd Login) authenticate(c *cli.Context) { usernameFlagValue := c.String("u") passwordFlagValue := c.String("p") prompts, err := cmd.authenticator.GetLoginPromptsAndSaveUAAServerURL() if err != nil { cmd.ui.Failed(err.Error()) } passwordKeys := []string{} credentials := make(map[string]string) for key, prompt := range prompts { if prompt.Type == configuration.AuthPromptTypePassword { passwordKeys = append(passwordKeys, key) } else if key == "username" && usernameFlagValue != "" { credentials[key] = usernameFlagValue } else { credentials[key] = cmd.ui.Ask("%s%s", prompt.DisplayName, terminal.PromptColor(">")) } } for i := 0; i < maxLoginTries; i++ { for _, key := range passwordKeys { if key == "password" && passwordFlagValue != "" { credentials[key] = passwordFlagValue passwordFlagValue = "" } else { credentials[key] = cmd.ui.AskForPassword("%s%s", prompts[key].DisplayName, terminal.PromptColor(">")) } } cmd.ui.Say("Authenticating...") err = cmd.authenticator.Authenticate(credentials) if err == nil { cmd.ui.Ok() cmd.ui.Say("") break } cmd.ui.Say(err.Error()) } if err != nil { cmd.ui.Failed("Unable to authenticate.") } }
func (cmd *DeleteSpace) Run(c *cli.Context) { spaceName := c.Args()[0] force := c.Bool("f") cmd.ui.Say("Deleting space %s in org %s as %s...", terminal.EntityNameColor(spaceName), terminal.EntityNameColor(cmd.config.Organization.Name), terminal.EntityNameColor(cmd.config.Username()), ) space, apiResponse := cmd.spaceRepo.FindByName(spaceName) if apiResponse.IsError() { cmd.ui.Failed(apiResponse.Message) return } if apiResponse.IsNotFound() { cmd.ui.Ok() cmd.ui.Warn("Space %s does not exist.", spaceName) return } if !force { response := cmd.ui.Confirm( "Really delete space %s and everything associated with it?%s", terminal.EntityNameColor(spaceName), terminal.PromptColor(">"), ) if !response { return } } apiResponse = cmd.spaceRepo.Delete(space) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Ok() config, err := cmd.configRepo.Get() if err != nil { cmd.ui.ConfigFailure(err) return } if config.Space.Name == spaceName { config.Space = cf.Space{} cmd.configRepo.Save() cmd.ui.Say("TIP: No space targeted, use '%s target -s' to target a space", cf.Name()) } return }
func (cmd Login) authenticate(c *cli.Context) { prompts, err := cmd.authenticator.GetLoginPromptsAndSaveUAAServerURL() if err != nil { cmd.ui.Failed(err.Error()) } var passwordKey string credentials := make(map[string]string) for key, prompt := range prompts { if prompt.Type == configuration.AuthPromptTypePassword { passwordKey = key } else if key == "username" && c.String("u") != "" { credentials[key] = c.String("u") } else { credentials[key] = cmd.ui.Ask("%s%s", prompt.DisplayName, terminal.PromptColor(">")) } } password := c.String("p") passwordPrompt := prompts[passwordKey] for i := 0; i < maxLoginTries; i++ { if password == "" || i > 0 { password = cmd.ui.AskForPassword("%s%s", passwordPrompt.DisplayName, terminal.PromptColor(">")) } cmd.ui.Say("Authenticating...") credentials[passwordKey] = password err = cmd.authenticator.Authenticate(credentials) if err == nil { cmd.ui.Ok() cmd.ui.Say("") break } cmd.ui.Say(err.Error()) } if err != nil { cmd.ui.Failed("Unable to authenticate.") } }
func (cmd *DeleteOrg) Run(c *cli.Context) { orgName := c.Args()[0] force := c.Bool("f") if !force { response := cmd.ui.Confirm( "Really delete org %s and everything associated with it?%s", terminal.EntityNameColor(orgName), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting org %s as %s...", terminal.EntityNameColor(orgName), terminal.EntityNameColor(cmd.config.Username()), ) org, apiResponse := cmd.orgRepo.FindByName(orgName) if apiResponse.IsError() { cmd.ui.Failed(apiResponse.Message) return } if apiResponse.IsNotFound() { cmd.ui.Ok() cmd.ui.Warn("Org %s does not exist.", orgName) return } apiResponse = cmd.orgRepo.Delete(org) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } config, err := cmd.configRepo.Get() if err != nil { cmd.ui.Failed("Couldn't reset your target. You should logout and log in again.") return } if org.Guid == config.Organization.Guid { config.Organization = cf.Organization{} config.Space = cf.Space{} cmd.configRepo.Save() } cmd.ui.Ok() return }
func (cmd *DeleteApp) Run(c *cli.Context) { appName := c.Args()[0] if !c.Bool("f") { response := cmd.ui.Confirm( "Really delete %s?%s", terminal.EntityNameColor(appName), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting app %s in org %s / space %s as %s...", terminal.EntityNameColor(appName), terminal.EntityNameColor(cmd.config.OrganizationFields().Name), terminal.EntityNameColor(cmd.config.SpaceFields().Name), terminal.EntityNameColor(cmd.config.Username()), ) app, apiErr := cmd.appRepo.Read(appName) switch apiErr.(type) { case nil: // no error case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn("App %s does not exist.", appName) return default: cmd.ui.Failed(apiErr.Error()) return } if c.Bool("r") { for _, route := range app.Routes { apiErr = cmd.routeRepo.Delete(route.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } } } apiErr = cmd.appRepo.Delete(app.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() return }
func (l Login) Run(c *cli.Context) { l.ui.Say("API endpoint: %s", term.EntityNameColor(l.config.Target)) var ( username string password string ) if len(c.Args()) > 0 { username = c.Args()[0] } else { username = l.ui.Ask("Username%s", term.PromptColor(">")) } if len(c.Args()) > 1 { password = c.Args()[1] l.ui.Say("Authenticating...") apiErr := l.doLogin(username, password) if apiErr != nil { l.ui.Failed(apiErr.Error()) return } } else { for i := 0; i < maxLoginTries; i++ { password = l.ui.AskForPassword("Password%s", term.PromptColor(">")) l.ui.Say("Authenticating...") apiErr := l.doLogin(username, password) if apiErr != nil { l.ui.Failed(apiErr.Error()) continue } return } } return }
func (cmd Login) authenticate(c *cli.Context) (apiResponse net.ApiResponse) { prompts, apiResponse := cmd.authenticator.GetLoginPrompts() var passwordKey string credentials := make(map[string]string) for key, prompt := range prompts { if prompt.Type == configuration.AuthPromptTypePassword { passwordKey = key } else if key == "username" && c.String("u") != "" { credentials[key] = c.String("u") } else { credentials[key] = cmd.ui.Ask("%s%s", prompt.DisplayName, terminal.PromptColor(">")) } } password := c.String("p") passwordPrompt := prompts[passwordKey] for i := 0; i < maxLoginTries; i++ { if password == "" || i > 0 { password = cmd.ui.AskForPassword("%s%s", passwordPrompt.DisplayName, terminal.PromptColor(">")) } cmd.ui.Say("Authenticating...") credentials[passwordKey] = password apiResponse = cmd.authenticator.Authenticate(credentials) if apiResponse.IsSuccessful() { cmd.ui.Ok() cmd.ui.Say("") break } cmd.ui.Say(apiResponse.Message) } return }
func (cmd *DeleteOrg) Run(c *cli.Context) { orgName := c.Args()[0] force := c.Bool("f") if !force { response := cmd.ui.Confirm( "Really delete org %s and everything associated with it?%s", terminal.EntityNameColor(orgName), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting org %s as %s...", terminal.EntityNameColor(orgName), terminal.EntityNameColor(cmd.config.Username()), ) org, apiErr := cmd.orgRepo.FindByName(orgName) switch apiErr.(type) { case nil: case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn("Org %s does not exist.", orgName) return default: cmd.ui.Failed(apiErr.Error()) return } apiErr = cmd.orgRepo.Delete(org.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } if org.Guid == cmd.config.OrganizationFields().Guid { cmd.config.SetOrganizationFields(models.OrganizationFields{}) cmd.config.SetSpaceFields(models.SpaceFields{}) } cmd.ui.Ok() return }
func (cmd *DeleteOrg) Run(c *cli.Context) { orgName := c.Args()[0] force := c.Bool("f") if !force { response := cmd.ui.Confirm( "Really delete org %s and everything associated with it?%s", terminal.EntityNameColor(orgName), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting org %s as %s...", terminal.EntityNameColor(orgName), terminal.EntityNameColor(cmd.config.Username()), ) org, apiResponse := cmd.orgRepo.FindByName(orgName) if apiResponse.IsError() { cmd.ui.Failed(apiResponse.Message) return } if apiResponse.IsNotFound() { cmd.ui.Ok() cmd.ui.Warn("Org %s does not exist.", orgName) return } apiResponse = cmd.orgRepo.Delete(org.Guid) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } if org.Guid == cmd.config.OrganizationFields().Guid { cmd.config.SetOrganizationFields(models.OrganizationFields{}) cmd.config.SetSpaceFields(models.SpaceFields{}) } cmd.ui.Ok() return }
func (cmd Login) decideEndpoint(c *cli.Context) (string, bool) { endpoint := c.String("a") skipSSL := c.Bool("skip-ssl-validation") if endpoint == "" { endpoint = cmd.config.ApiEndpoint() skipSSL = cmd.config.IsSSLDisabled() || skipSSL } if endpoint == "" { endpoint = cmd.ui.Ask("API endpoint%s", terminal.PromptColor(">")) } else { cmd.ui.Say("API endpoint: %s", terminal.EntityNameColor(endpoint)) } return endpoint, skipSSL }
func (cmd *DeleteApp) Run(c *cli.Context) { appName := c.Args()[0] force := c.Bool("f") if !force { response := cmd.ui.Confirm( "Really delete %s?%s", terminal.EntityNameColor(appName), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting app %s in org %s / space %s as %s...", terminal.EntityNameColor(appName), terminal.EntityNameColor(cmd.config.Organization.Name), terminal.EntityNameColor(cmd.config.Space.Name), terminal.EntityNameColor(cmd.config.Username()), ) app, apiResponse := cmd.appRepo.FindByName(appName) if apiResponse.IsError() { cmd.ui.Failed(apiResponse.Message) return } if apiResponse.IsNotFound() { cmd.ui.Ok() cmd.ui.Warn("App %s does not exist.", appName) return } apiResponse = cmd.appRepo.Delete(app) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Ok() return }
func (cmd *DeleteRoute) Run(c *cli.Context) { host := c.String("n") domainName := c.Args()[0] url := domainName if host != "" { url = host + "." + domainName } force := c.Bool("f") if !force { response := cmd.ui.Confirm( "Really delete route %s?%s", terminal.EntityNameColor(url), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting route %s...", terminal.EntityNameColor(url)) route, apiErr := cmd.routeRepo.FindByHostAndDomain(host, domainName) switch apiErr.(type) { case nil: case errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn("Route %s does not exist.", url) return default: cmd.ui.Failed(apiErr.Error()) return } apiErr = cmd.routeRepo.Delete(route.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() }
func (cmd CreateService) createUserProvidedService(name string, params string) { paramsMap := make(map[string]string) params = strings.Trim(params, `"`) for _, param := range strings.Split(params, ",") { param = strings.Trim(param, " ") paramsMap[param] = cmd.ui.Ask("%s%s", param, term.PromptColor(">")) } cmd.ui.Say("Creating service...") err := cmd.serviceRepo.CreateUserProvidedServiceInstance(name, paramsMap) if err != nil { cmd.ui.Failed(err.Error()) return } cmd.ui.Ok() return }
func (cmd *DeleteRoute) Run(c *cli.Context) { host := c.String("n") domainName := c.Args()[0] url := domainName if host != "" { url = host + "." + domainName } force := c.Bool("f") if !force { response := cmd.ui.Confirm( "Really delete route %s?%s", terminal.EntityNameColor(url), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting route %s...", terminal.EntityNameColor(url)) route, apiResponse := cmd.routeRepo.FindByHostAndDomain(host, domainName) if apiResponse.IsError() { cmd.ui.Failed(apiResponse.Message) return } if apiResponse.IsNotFound() { cmd.ui.Ok() cmd.ui.Warn("Route %s does not exist.", url) return } apiResponse = cmd.routeRepo.Delete(route.Guid) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Ok() }
func (cmd DeleteServiceBroker) Run(c *cli.Context) { brokerName := c.Args()[0] force := c.Bool("f") if !force { response := cmd.ui.Confirm( "Really delete %s?%s", terminal.EntityNameColor(brokerName), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting service broker %s as %s...", terminal.EntityNameColor(brokerName), terminal.EntityNameColor(cmd.config.Username()), ) broker, apiResponse := cmd.repo.FindByName(brokerName) if apiResponse.IsError() { cmd.ui.Failed(apiResponse.Message) return } if apiResponse.IsNotFound() { cmd.ui.Ok() cmd.ui.Warn("Service Broker %s does not exist.", brokerName) return } apiResponse = cmd.repo.Delete(broker) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Ok() return }
func (cmd DeleteServiceBroker) Run(c *cli.Context) { brokerName := c.Args()[0] force := c.Bool("f") if !force { response := cmd.ui.Confirm( "Really delete %s?%s", terminal.EntityNameColor(brokerName), terminal.PromptColor(">"), ) if !response { return } } cmd.ui.Say("Deleting service broker %s as %s...", terminal.EntityNameColor(brokerName), terminal.EntityNameColor(cmd.config.Username()), ) broker, apiErr := cmd.repo.FindByName(brokerName) switch apiErr.(type) { case nil: case errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn("Service Broker %s does not exist.", brokerName) return default: cmd.ui.Failed(apiErr.Error()) return } apiErr = cmd.repo.Delete(broker.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() return }
func (cmd Login) setApi(c *cli.Context) (apiResponse net.ApiResponse) { api := c.String("a") if api == "" { api = cmd.config.Target } if api == "" { api = cmd.ui.Ask("API endpoint%s", terminal.PromptColor(">")) } else { cmd.ui.Say("API endpoint: %s", terminal.EntityNameColor(api)) } endpoint, apiResponse := cmd.endpointRepo.UpdateEndpoint(api) if !strings.HasPrefix(endpoint, "https://") { cmd.ui.Say(terminal.WarningColor("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n")) } return }
func (cmd *DeleteSpace) Run(c *cli.Context) { spaceName := c.Args()[0] force := c.Bool("f") cmd.ui.Say("Deleting space %s in org %s as %s...", terminal.EntityNameColor(spaceName), terminal.EntityNameColor(cmd.config.OrganizationFields().Name), terminal.EntityNameColor(cmd.config.Username()), ) space := cmd.spaceReq.GetSpace() if !force { response := cmd.ui.Confirm( "Really delete space %s and everything associated with it?%s", terminal.EntityNameColor(spaceName), terminal.PromptColor(">"), ) if !response { return } } apiResponse := cmd.spaceRepo.Delete(space.Guid) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Ok() if cmd.config.SpaceFields().Name == spaceName { cmd.config.SetSpaceFields(models.SpaceFields{}) cmd.ui.Say("TIP: No space targeted, use '%s target -s' to target a space", cf.Name()) } return }