Пример #1
0
func loadThemeClientWithRetry(directory, env string, isRetry bool) (themekit.ThemeClient, error) {
	environments, err := loadEnvironments(directory)
	if err != nil {
		return themekit.ThemeClient{}, err
	}
	config, err := environments.GetConfiguration(env)
	if err != nil && len(environments) > 0 {
		invalidEnvMsg := fmt.Sprintf("'%s' is not a valid environment. The following environments are available within config.yml:", env)
		fmt.Println(themekit.RedText(invalidEnvMsg))
		for e, _ := range environments {
			fmt.Println(themekit.RedText(fmt.Sprintf(" - %s", e)))
		}
		os.Exit(1)
	} else if err != nil && !isRetry {
		upgradeMessage := fmt.Sprintf("Looks like your configuration file is out of date. Upgrading to default environment '%s'", themekit.DefaultEnvironment)
		fmt.Println(themekit.YellowText(upgradeMessage))
		confirmationfn, savefn := commands.PrepareConfigurationMigration(directory)

		if confirmationfn() && savefn() == nil {
			return loadThemeClientWithRetry(directory, env, true)
		}

		return themekit.ThemeClient{}, errors.New("loadThemeClientWithRetry: could not load or migrate the configuration")
	} else if err != nil {
		return themekit.ThemeClient{}, err
	}

	return themekit.NewThemeClient(config), nil
}
Пример #2
0
func extractThemeClients(args map[string]interface{}) []themekit.ThemeClient {
	if args["environments"] == nil {
		return []themekit.ThemeClient{}
	}

	var ok bool
	var environments themekit.Environments
	if environments, ok = args["environments"].(themekit.Environments); !ok {
		themekit.NotifyError(errors.New("environments is not of a valid type"))
	}
	clients := make([]themekit.ThemeClient, len(environments), len(environments))
	idx := 0
	for _, configuration := range environments {
		clients[idx] = themekit.NewThemeClient(configuration)
		idx++
	}
	return clients
}