<commit_before>package bcr_prompts

import (
	"bufio"
	"encoding/json"
	"errors"
	"fmt"
	cf_terminal "github.com/cloudfoundry/cli/cf/terminal"
	"github.com/cloudfoundry/cli/plugin"
	"github.com/ibmjstart/bluemix-cloudant-replicator/CloudantAccountModel"
	"github.com/ibmjstart/bluemix-cloudant-replicator/utils"
	"golang.org/x/crypto/ssh/terminal"
	"io/ioutil"
	"net/http"
	"os"
	"strconv"
	"strings"
)

func init() {
	cf_terminal.InitColorSupport()
}

func GetPassword() string {
	fmt.Print("\nBluemix password to log in across multiple regions.\n")
	fmt.Print("\nPassword" + cf_terminal.ColorizeBold(">", 36))
	pw, _ := terminal.ReadPassword(0)
	fmt.Println("\n")
	return string(pw)
}

/*
*	Requests all databases for a given Cloudant account
*	and returns them as a string array
 */
func GetAllDatabases(httpClient *http.Client, account cam.CloudantAccount) []string {
	url := "http://" + account.Username + ".cloudant.com/_all_dbs"
	headers := map[string]string{"Cookie": account.Cookie}
	resp, _ := bcr_utils.MakeRequest(httpClient, "GET", url, "", headers)
	respBody, _ := ioutil.ReadAll(resp.Body)
	dbsStr := string(respBody)
	var dbs []string
	json.Unmarshal([]byte(dbsStr), &dbs)
	resp.Body.Close()
	var noRepDbs []string
	for i := 0; i < len(dbs); i++ {
		if dbs[i] != "_replicator" {
			noRepDbs = append(noRepDbs, dbs[i])
		}
	}
	return noRepDbs
}

/*
*	Lists all databases for a specified CloudantAccount and
*	prompts the user to select one
 */
func GetDatabases(httpClient *http.Client, account cam.CloudantAccount) ([]string, error) {
	reader := bufio.NewReader(os.Stdin)
	all_dbs := GetAllDatabases(httpClient, account)
	if len(all_dbs) == 0 {
		return all_dbs, errors.New("No databases found for CloudantNoSQLDB service in '" + account.Endpoint + "'")
	}
	fmt.Println("Current databases:\n")
	for i := 0; i < len(all_dbs); i++ {
		fmt.Println(strconv.Itoa(i+1) + ". " + cf_terminal.ColorizeBold(all_dbs[i], 36))
	}
	if len(all_dbs) > 1 {
		fmt.Println(strconv.Itoa(len(all_dbs)+1) + ". sync all databases")
	}
	fmt.Print("\nWhich database would you like to sync?" + cf_terminal.ColorizeBold(">", 36))
	d, _, _ := reader.ReadLine()
	selected_dbs := strings.Split(string(d), ",")
	fmt.Println()
	var dbs []string
	for i := 0; i < len(selected_dbs); i++ {
		if j, err := strconv.Atoi(selected_dbs[i]); err == nil {
			if j <= len(all_dbs) && j > 0 {
				dbs = append(dbs, all_dbs[j-1])<commit_msg>added coloring for an endpoint<commit_after>package bcr_prompts

import (
	"bufio"
	"encoding/json"
	"errors"
	"fmt"
	cf_terminal "github.com/cloudfoundry/cli/cf/terminal"
	"github.com/cloudfoundry/cli/plugin"
	"github.com/ibmjstart/bluemix-cloudant-replicator/CloudantAccountModel"
	"github.com/ibmjstart/bluemix-cloudant-replicator/utils"
	"golang.org/x/crypto/ssh/terminal"
	"io/ioutil"
	"net/http"
	"os"
	"strconv"
	"strings"
)

func init() {
	cf_terminal.InitColorSupport()
}

func GetPassword() string {
	fmt.Print("\nBluemix password to log in across multiple regions.\n")
	fmt.Print("\nPassword" + cf_terminal.ColorizeBold(">", 36))
	pw, _ := terminal.ReadPassword(0)
	fmt.Println("\n")
	return string(pw)
}

/*
*	Requests all databases for a given Cloudant account
*	and returns them as a string array
 */
func GetAllDatabases(httpClient *http.Client, account cam.CloudantAccount) []string {
	url := "http://" + account.Username + ".cloudant.com/_all_dbs"
	headers := map[string]string{"Cookie": account.Cookie}
	resp, _ := bcr_utils.MakeRequest(httpClient, "GET", url, "", headers)
	respBody, _ := ioutil.ReadAll(resp.Body)
	dbsStr := string(respBody)
	var dbs []string
	json.Unmarshal([]byte(dbsStr), &dbs)
	resp.Body.Close()
	var noRepDbs []string
	for i := 0; i < len(dbs); i++ {
		if dbs[i] != "_replicator" {
			noRepDbs = append(noRepDbs, dbs[i])
		}
	}
	return noRepDbs
}

/*
*	Lists all databases for a specified CloudantAccount and
*	prompts the user to select one
 */
func GetDatabases(httpClient *http.Client, account cam.CloudantAccount) ([]string, error) {
	reader := bufio.NewReader(os.Stdin)
	all_dbs := GetAllDatabases(httpClient, account)
	if len(all_dbs) == 0 {
		return all_dbs, errors.New("No databases found for CloudantNoSQLDB service in '" +
			cf_terminal.ColorizeBold(account.Endpoint, 36) + "'")
	}
	fmt.Println("Current databases:\n")
	for i := 0; i < len(all_dbs); i++ {
		fmt.Println(strconv.Itoa(i+1) + ". " + cf_terminal.ColorizeBold(all_dbs[i], 36))
	}
	if len(all_dbs) > 1 {
		fmt.Println(strconv.Itoa(len(all_dbs)+1) + ". sync all databases")
	}
	fmt.Print("\nWhich database would you like to sync?" + cf_terminal.ColorizeBold(">", 36))
	d, _, _ := reader.ReadLine()
	selected_dbs := strings.Split(string(d), ",")
	fmt.Println()
	var dbs []string
	for i := 0; i < len(selected_dbs); i++ {
		if j, err := strconv.Atoi(selected_dbs[i]); err == nil {
			if j <= len(all_dbs) && j > 0 {
				dbs = append(dbs, all_dbs[j-1])
{'fraction_non_alphanumeric': 0.16249487074271646, 'fraction_numerical': 0.006975789905621666, 'mean_word_length': 4.62933025404157, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1024662', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1890, 'n_words': 392}