config.go
func CreateConfig(path string) error {
	config, _ := LoadConfig(path)
	var emailDef, passwordDef, accountDef, hostDef, refreshTokenDef string
	if config != nil {
		yn := PromptConfirmation("Found existing configuration file %v, overwrite? (y/N): ", path)
		if yn != "y" {
			PrintSuccess("Exiting")
			return nil
		}
		emailDef = fmt.Sprintf(" (%v)", config.Email)
		accountDef = fmt.Sprintf(" (%v)", config.Account)
		passwordDef = " (leave blank to leave unchanged)"
		if config.LoginHost == "" {
			config.LoginHost = "my.rightscale.com"
		}
		hostDef = fmt.Sprintf(" (%v)", config.LoginHost)
		refreshTokenDef = " (leave blank to leave unchanged)"
	} else {
		config = &ClientConfig{}
	}

	fmt.Fprintf(out, "Account ID%v: ", accountDef)
	var newAccount string
	fmt.Fscanln(in, &newAccount)
	if newAccount != "" {
		a, err := strconv.Atoi(newAccount)
		if err != nil {
			return fmt.Errorf("Account ID must be an integer, got '%s'.", newAccount)
		}
		config.Account = a
	}

	fmt.Fprintf(out, "Login email%v: ", emailDef)
	var newEmail string
	fmt.Fscanln(in, &newEmail)
	if newEmail != "" {
		config.Email = newEmail
	}

	fmt.Fprintf(out, "Login password%v: ", passwordDef)
	var newPassword string
	fmt.Fscanln(in, &newPassword)
	if newPassword != "" {
		config.Password = newPassword
	}

	fmt.Fprintf(out, "API Login host%v: ", hostDef)
	var newLoginHost string
	fmt.Fscanln(in, &newLoginHost)
	if newLoginHost != "" {
		config.LoginHost = newLoginHost
	}

	fmt.Fprintf(out, "API Refresh Token%v: ", refreshTokenDef)
	var newRefreshToken string
	fmt.Fscanln(in, &newRefreshToken)
	if newRefreshToken != "" {
		config.RefreshToken = newRefreshToken
	}

	err := config.Save(path)
	if err != nil {
		return fmt.Errorf("Failed to save config: %s", err)
	}

	return nil
}
func CreateConfig(path string) error {
	config, _ := LoadConfig(path)
	var emailDef, passwordDef, accountDef, hostDef, refreshTokenDef string
	if config != nil {
		yn := PromptConfirmation("Found existing configuration file %v, overwrite? (y/N): ", path)
		if yn != "y" {
			PrintSuccess("Exiting")
			return nil
		}
		emailDef = fmt.Sprintf(" (%v)", config.Email)
		accountDef = fmt.Sprintf(" (%v)", config.Account)
		passwordDef = " (leave blank to leave unchanged)"
		if config.LoginHost == "" {
			config.LoginHost = "my.rightscale.com"
		}
		hostDef = fmt.Sprintf(" (%v)", config.LoginHost)
		refreshTokenDef = " (leave blank to leave unchanged)"
	} else {
		config = &ClientConfig{}
	}

	fmt.Fprintf(out, "Account ID%v: ", accountDef)
	var newAccount string
	fmt.Fscanln(in, &newAccount)
	if newAccount != "" {
		a, err := strconv.Atoi(newAccount)
		if err != nil {
			return fmt.Errorf("Account ID must be an integer, got '%s'.", newAccount)
		}
		config.Account = a
	}

	fmt.Fprintf(out, "Login email%v: ", emailDef)
	var newEmail string
	fmt.Fscanln(in, &newEmail)
	if newEmail != "" {
		config.Email = newEmail
	}

	fmt.Fprintf(out, "Login password%v: ", passwordDef)
	var newPassword string
	fmt.Fscanln(in, &newPassword)
	if newPassword != "" {
		config.Password = newPassword
	}

	fmt.Fprintf(out, "API Login host%v: ", hostDef)
	var newLoginHost string
	fmt.Fscanln(in, &newLoginHost)
	if newLoginHost != "" {
		config.LoginHost = newLoginHost
	}

	fmt.Fprintf(out, "API Refresh Token%v: ", refreshTokenDef)
	var newRefreshToken string
	fmt.Fscanln(in, &newRefreshToken)
	if newRefreshToken != "" {
		config.RefreshToken = newRefreshToken
	}

	err := config.Save(path)
	if err != nil {
		return fmt.Errorf("Failed to save config: %s", err)
	}

	return nil
}
// CreateConfig creates a configuration file and saves it to the file at the given path.