예제 #1
0
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
}
func (w *TemplateWriterBase) shouldOverwriteExistingFile(filename string) bool {
	if !common.FileExists(filename) {
		return true
	}
	isStarterTemplate := w.isStarterTemplate(filename)
	if isStarterTemplate {
		return true
	}
	if !w.ShouldPrompt {
		return isStarterTemplate
	}

	answer := "none"
	for answer != "o" && answer != "r" && answer != "" {
		common.PrintL1("%s cannot be written as it already exists. What to do? [o: overwrite, R: rename] ", filepath.Base(filename))
		if _, err := fmt.Scanln(&answer); err != nil {
			return false
		}
		answer = strings.TrimSpace(strings.ToLower(answer))
	}
	return answer == "o"
}