Exemplo n.º 1
0
Arquivo: ui.go Projeto: fujitsu-cf/cli
func (ui *FakeUI) ConfirmDelete(modelType, modelName string) bool {
	return ui.Confirm(fmt.Sprintf(
		"Really delete the %s %s?%s",
		modelType,
		term.EntityNameColor(modelName),
		term.PromptColor(">")))
}
Exemplo n.º 2
0
func (cmd *DeleteOrphanedRoutes) Execute(c flags.FlagContext) error {
	force := c.Bool("f")
	if !force {
		response := cmd.ui.Confirm(T("Really delete orphaned routes?{{.Prompt}}",
			map[string]interface{}{"Prompt": terminal.PromptColor(">")}))

		if !response {
			return nil
		}
	}

	cmd.ui.Say(T("Getting routes as {{.Username}} ...\n",
		map[string]interface{}{"Username": terminal.EntityNameColor(cmd.config.Username())}))

	err := cmd.routeRepo.ListRoutes(func(route models.Route) bool {

		if len(route.Apps) == 0 {
			cmd.ui.Say(T("Deleting route {{.Route}}...",
				map[string]interface{}{"Route": terminal.EntityNameColor(route.URL())}))
			apiErr := cmd.routeRepo.Delete(route.GUID)
			if apiErr != nil {
				cmd.ui.Failed(apiErr.Error())
				return false
			}
		}
		return true
	})

	if err != nil {
		return errors.New(T("Failed fetching routes.\n{{.Err}}", map[string]interface{}{"Err": err.Error()}))
	}
	cmd.ui.Ok()
	return nil
}