예제 #1
0
func PrepareConfigurationMigration(dir string) (func() bool, func() error) {
	environmentLocation := filepath.Join(dir, "config.yml")
	env, err := loadOrInitializeEnvironment(environmentLocation)
	if err != nil {
		themekit.NotifyError(err)
		return func() bool { return false }, func() error { return err }
	}

	confirmationFn := func() bool {
		before, _ := ioutil.ReadFile(environmentLocation)
		after := env.String()
		fmt.Println(themekit.YellowText("Compare changes to configuration:"))
		fmt.Println(themekit.YellowText("Before:\n"), themekit.GreenText(string(before)))
		fmt.Println(themekit.YellowText("After:\n"), themekit.RedText(after))
		reader := bufio.NewReader(os.Stdin)
		fmt.Println(themekit.YellowText("Does this look correct? (y/n)"))
		text, _ := reader.ReadString('\n')
		return strings.TrimSpace(text) == "y"
	}

	saveFn := func() error {
		return env.Save(environmentLocation)
	}
	return confirmationFn, saveFn
}
예제 #2
0
파일: main.go 프로젝트: chuckhendo/themekit
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
}
예제 #3
0
func handleError(filename string, err error, eventLog chan themekit.ThemeEvent) {
	if nonFatal, ok := err.(themekit.NonFatalNetworkError); ok {
		event := basicEvent{
			Title:     "Non-Fatal Network Error",
			EventType: nonFatal.Verb,
			Target:    filename,
			etype:     "fsevent",
			Formatter: func(b basicEvent) string {
				return fmt.Sprintf(
					"[%s] Could not complete %s for %s",
					themekit.RedText(fmt.Sprintf("%d", nonFatal.Code)),
					themekit.YellowText(b.EventType),
					themekit.BlueText(b.Target),
				)
			},
		}
		logEvent(event, eventLog)
	}
}
예제 #4
0
파일: main.go 프로젝트: chuckhendo/themekit
func checkForUpdate() {
	if commands.IsNewReleaseAvailable() {
		message := fmt.Sprintf("%s\n%s\n%s", banner, updateAvailableMessage, banner)
		fmt.Println(themekit.YellowText(message))
	}
}