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 (a *AnalyzerBase) ConfirmVersion(found bool, version string, defaultVersion string) string { message := fmt.Sprintf("Found %s version %s, confirm?", a.GetPack().Name(), version) if found && common.AskYesOrNo(message, true, a.ShouldPrompt) { return version } return common.AskUserWithDefault(fmt.Sprintf("Enter %s version:", a.GetPack().Name()), defaultVersion, a.ShouldPrompt) }
func (a *Analyzer) findWSGIFile() (bool, string) { var found []string WSGIPattern := regexp.MustCompile("^(wsgi\\.py|.*\\.wsgi)$") filepath.Walk(a.RootDir, func(path string, info os.FileInfo, err error) error { if err != nil { return nil } if WSGIPattern.MatchString(filepath.Base(path)) { found = append(found, path) } return nil }) wsgi := "" if len(found) == 1 && common.AskYesOrNo(fmt.Sprintf("Found WSGI file %s, confirm?", found[0]), true, a.ShouldPrompt) { wsgi = found[0] } else if len(found) > 1 && a.ShouldPrompt { answer := common.AskMultipleChoices("Found several potential WSGI files. Please choose one:", append(found, "Other")) if answer != "Other" { wsgi = answer } } if wsgi == "" && a.ShouldPrompt { wsgi = common.AskUser("Enter WSGI file path") } return wsgi != "", wsgi }
func (a *AnalyzerBase) AskForCommand(defaultCommand string, step string) string { confirmed := defaultCommand != "" && common.AskYesOrNo(fmt.Sprintf("This command will be run after each %s: '%s', confirm?", step, defaultCommand), true, a.ShouldPrompt) if confirmed { return defaultCommand } else { return common.AskUserWithDefault(fmt.Sprintf("Enter command to run after each %s:", step), "", a.ShouldPrompt) } }