func()

in oss/lib/config.go [435:496]


func (cc *ConfigCommand) configInteractive(configFile, language string) error {
	var val string
	config := configparser.NewConfiguration()
	section := config.NewSection(CREDSection)

	// if config file not exist, config Language
	llanguage := strings.ToLower(language)
	section.Add(OptionLanguage, language)
	if _, err := os.Stat(configFile); err != nil {
		if llanguage == LEnglishLanguage {
			fmt.Printf("Please enter language(%s, default is:%s, the configuration will go into effect after the command successfully executed):", OptionMap[OptionLanguage].minVal, DefaultLanguage)
		} else {
			fmt.Printf("请输入语言(%s,默认为:%s,该配置项将在此次config命令成功结束后生效):", OptionMap[OptionLanguage].minVal, DefaultLanguage)
		}
		if _, err := fmt.Scanln(&val); err == nil {
			vals := strings.Split(OptionMap[OptionLanguage].minVal, "/")
			if FindPosCaseInsen(val, vals) == -1 {
				return fmt.Errorf("invalid option value of %s, the value: %s is not anyone of %s", OptionLanguage, val, OptionMap[OptionLanguage].minVal)
			}
			section.Add(OptionLanguage, val)
		}
	}

	for name, option := range CredOptionMap {
		if !option.cfInteractive {
			continue
		}
		str := ""
		if llanguage == LEnglishLanguage {
			if OptionMap[name].def != "" {
				str = fmt.Sprintf("(%sdefault is:%s, carriage return will use the default value)", option.helpEnglish, OptionMap[name].def)
			}
			fmt.Printf("Please enter %s%s:", name, str)
		} else {
			if OptionMap[name].def != "" {
				str = fmt.Sprintf("(%s默认为:%s,回车将使用默认值)", option.helpChinese, OptionMap[name].def)
			}
			fmt.Printf("请输入%s%s:", name, str)
		}

		// fmt.Scanln have 256 length limit on windows platform,so use Reader
		val = ""
		valueReader := bufio.NewReader(os.Stdin)
		val, _ = valueReader.ReadString('\n') // Need to pass '\n' as char (byte)
		if runtime.GOOS == "windows" {
			val = strings.TrimSuffix(val, "\r\n")
		} else {
			val = strings.TrimSuffix(val, "\n")
		}

		if len(val) > 0 {
			section.Add(name, val)
		} else if OptionMap[name].def != "" {
			section.Add(name, OptionMap[name].def)
		}
	}

	if err := configparser.Save(config, configFile); err != nil {
		return err
	}
	return nil
}