func (a *AnalyzerBase) ConfirmDatabases(foundDbs *common.Lister) *common.Lister {
	var dbs common.Lister
	for _, db := range foundDbs.Items {
		if !a.ShouldPrompt {
			common.PrintlnL2("Found %s", db)
		}
		if common.AskYesOrNo(fmt.Sprintf("Found %s, confirm?", db), true, a.ShouldPrompt) {
			dbs.Add(db)
		}
	}

	var message string
	var defaultValue bool
	if len(foundDbs.Items) > 0 {
		message = "Add any other databases?"
		defaultValue = false
	} else {
		message = "No databases found. Add manually?"
		defaultValue = true
	}

	if common.AskYesOrNo(message, defaultValue, a.ShouldPrompt) && a.ShouldPrompt {
		common.PrintlnL1("  See http://help.cloud66.com/building-your-stack/docker-service-configuration#database-configs for complete list of possible values")
		common.PrintlnL1("  Example: 'mysql elasticsearch' ")
		common.PrintL1("> ")

		reader := bufio.NewReader(os.Stdin)
		otherDbs, err := reader.ReadString('\n')
		if err == nil {
			dbs.Add(strings.Fields(otherDbs)...)
		}
	}
	return &dbs
}
Exemple #2
0
// downloading templates from github and putting them into homedir
func getTempaltes(tempDir string) error {
	common.PrintlnL0("Checking templates in %s", tempDir)

	var tv templateDefinition
	err := fetchJSON(strings.Replace(templatePath, "{{.branch}}", flagBranch, -1), nil, &tv)
	if err != nil {
		return err
	}

	// is there a local copy?
	if _, err := os.Stat(filepath.Join(tempDir, "templates.json")); os.IsNotExist(err) {
		// no file. downloading
		common.PrintlnL1("No local templates found. Downloading now.")
		err := os.MkdirAll(tempDir, 0777)
		if err != nil {
			return err
		}

		err = downloadTemplates(tempDir, tv)
		if err != nil {
			return err
		}
	}

	// load the local json
	templatesLocal, err := ioutil.ReadFile(filepath.Join(tempDir, "templates.json"))
	if err != nil {
		return err
	}
	var localTv templateDefinition
	err = json.Unmarshal(templatesLocal, &localTv)
	if err != nil {
		return err
	}

	// compare
	if localTv.Version != tv.Version {
		common.PrintlnL2("Newer templates found. Downloading them now")
		// they are different, we need to download the new ones
		err = downloadTemplates(tempDir, tv)
		if err != nil {
			return err
		}
	} else {
		common.PrintlnL1("Local templates are up to date")
	}

	return nil
}