<commit_before>package cmd

import (
	"bufio"
	"encoding/json"
	"errors"
	"flag"
	"fmt"
	"github.com/alexzorin/onapp"
	"github.com/alexzorin/onapp/cmd/log"
	"io/ioutil"
	"os"
	"os/user"
	"path/filepath"
	"reflect"
	"strings"
)

const (
	configCmdDescription = "Configure this tool"
	configCmdHelp        = "This command is an interactive wizard to help you setup this tool.\n" +
		"You will need your OnApp dashboard URL, email address and API key to complete it."
)

type config struct {
	ConfigFile string
	ApiUser    string
	ApiKey     string
	Server     string
	Verbose    bool
}

type configCmd struct {
}

func (c configCmd) Run(args []string, ctx *cli) error {

	log.Infoln("This is the configuration wizard. Please provide the following: \n")
	reader := bufio.NewReader(os.Stdin)

	log.Infof("Hostname of the OnApp dashboard: ")
	host, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	log.Infof("API Username (generally the email address): ")
	user, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	log.Infof("API Key: ")
	apiKey, err := reader.ReadString('\n')
	if err != nil {
		return err
	}

	log.Infof("Test these details? [yes/no]: ")
	doTest, err := reader.ReadString('\n')
	if err != nil {
		return err
	}

	ctx.config.Server = strings.Trim(host, "\r\n")
	ctx.config.ApiUser = strings.Trim(user, "\r\n")
	ctx.config.ApiKey = strings.Trim(apiKey, "\r\n")

	if strings.ToLower(doTest)[0] == 'y' {
		err := c.testCredentials(ctx.config.Server, ctx.config.ApiUser, ctx.config.ApiKey)
		if err != nil {
			return err
		}
	}

	err = ctx.config.save()
	if err != nil {
		log.Errorln(err)
	} else {
		log.Infoln("\nSaved configuration to", ctx.config.ConfigFile)
	}

	return nil
}

func (c configCmd) testCredentials(host string, user string, pass string) error {
	client, err := onapp.NewClient(host, user, pass)
	if err != nil {
		return err
	}
	_, err := client.GetProfile()
	if err != nil {
		return err
	}
	return nil
}
<commit_msg>and still broken<commit_after>package cmd

import (
	"bufio"
	"encoding/json"
	"errors"
	"flag"
	"fmt"
	"github.com/alexzorin/onapp"
	"github.com/alexzorin/onapp/cmd/log"
	"io/ioutil"
	"os"
	"os/user"
	"path/filepath"
	"reflect"
	"strings"
)

const (
	configCmdDescription = "Configure this tool"
	configCmdHelp        = "This command is an interactive wizard to help you setup this tool.\n" +
		"You will need your OnApp dashboard URL, email address and API key to complete it."
)

type config struct {
	ConfigFile string
	ApiUser    string
	ApiKey     string
	Server     string
	Verbose    bool
}

type configCmd struct {
}

func (c configCmd) Run(args []string, ctx *cli) error {

	log.Infoln("This is the configuration wizard. Please provide the following: \n")
	reader := bufio.NewReader(os.Stdin)

	log.Infof("Hostname of the OnApp dashboard: ")
	host, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	log.Infof("API Username (generally the email address): ")
	user, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	log.Infof("API Key: ")
	apiKey, err := reader.ReadString('\n')
	if err != nil {
		return err
	}

	log.Infof("Test these details? [yes/no]: ")
	doTest, err := reader.ReadString('\n')
	if err != nil {
		return err
	}

	ctx.config.Server = strings.Trim(host, "\r\n")
	ctx.config.ApiUser = strings.Trim(user, "\r\n")
	ctx.config.ApiKey = strings.Trim(apiKey, "\r\n")

	if strings.ToLower(doTest)[0] == 'y' {
		err := c.testCredentials(ctx.config.Server, ctx.config.ApiUser, ctx.config.ApiKey)
		if err != nil {
			return err
		}
	}

	err = ctx.config.save()
	if err != nil {
		log.Errorln(err)
	} else {
		log.Infoln("\nSaved configuration to", ctx.config.ConfigFile)
	}

	return nil
}

func (c configCmd) testCredentials(host string, user string, pass string) error {
	client, err := onapp.NewClient(host, user, pass)
	if err != nil {
		return err
	}
	_, err = client.GetProfile()
	if err != nil {
		return err
	}
	return nil
}

{'fraction_non_alphanumeric': 0.1423154701718908, 'fraction_numerical': 0.0005055611729019212, 'mean_word_length': 3.4914869466515324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2040222', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1458, 'n_words': 396}