<commit_before>package commands

// -- Contains helper functions

import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"runtime"
	"strconv"
	"strings"
	"time"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/cloudformation"
	"github.com/aws/aws-sdk-go/service/s3"
	"github.com/ttacon/chalk"
)

// configTemplate - Returns template byte string for init() function
func configTemplate(project string, region string) []byte {
	return []byte(fmt.Sprintf(`
# Specify the AWS region code
# qaz will attempt to get it from AWS configuration
# or from the environment. This setting overrides
# every other.

region: %s

# Required: specify the name of the Project
# (qaz will prepend this value to the stack
# names defined below.

project: %s

# Optional: global values accisible accross
# all stacks can be define under global

global:

# Stack-specific variables and
# arbitrary keys cab be defined here,
# Under the [stacks] key word,

stacks:
  # Note that the stack name must match the file name of the template file. The extension does not need to be specified.
  your_stack_name_here:
    cf:
      your_key/value_pairs_here:
`, region, project))
}

// colorMap - Used to map a particular color to a cf status phrase - returns lowercase strings in color.
func colorMap(s string) string {

	// If Windows, disable colorS
	if runtime.GOOS == "windows" {
		return s
	}

	v := strings.Split(s, "_")[len(strings.Split(s, "_"))-1]

	var result string

	switch v {
	case "COMPLETE":
		result = chalk.Green.Color(s)
	case "PROGRESS":
		result = chalk.Yellow.Color(s)
	case "FAILED":
		result = chalk.Red.Color(s)
	case "SKIPPED":
		result = chalk.Blue.Color(s)
	default:
		// Unidentified, just returns the same string
		return strings.ToLower(s)
	}
	return strings.ToLower(result)
}

// colorString - Returns colored string
func colorString(s string, color string) string {

	// If Windows, disable colorS
	if runtime.GOOS == "windows" {
		return s
	}

	var result string
	switch strings.ToLower(color) {
	case "green":
		result = chalk.Green.Color(s)
	case "yellow":
		result = chalk.Yellow.Color(s)
	case "red":
		result = chalk.Red.Color(s)
	case "magenta":
		result = chalk.Magenta.Color(s)
	default:
		// Unidentified, just returns the same string
		return s
	}

	return result
}

// verbose - Takes a stackname and tracks the progress of creating the stack. s - stackname, c - command Type
func verbose(s string, c string, session *session.Session) {
	svc := cloudformation.New(session)

	params := &cloudformation.DescribeStackEventsInput{
		StackName: aws.String(s),
	}

	// used to track what lines have already been printed, to prevent dubplicate output
	printed := make(map[string]interface{})

	for {
		Log(fmt.Sprintf("Calling [DescribeStackEvents] with parameters: %s", params), level.debug)
		stackevents, err := svc.DescribeStackEvents(params)
		if err != nil {
			Log(fmt.Sprintln("Error when tailing events: ", err.Error()), level.debug)
		}

		Log(fmt.Sprintln("Response:", stackevents), level.debug)

		for _, event := range stackevents.StackEvents {

			statusReason := ""
			if strings.Contains(*event.ResourceStatus, "FAILED") {
				statusReason = *event.ResourceStatusReason
			}

			line := strings.Join([]string{
				colorMap(*event.ResourceStatus),
				*event.StackName,
				*event.ResourceType,
				*event.LogicalResourceId,
				statusReason,
			}, " - ")

			if _, ok := printed[line]; !ok {
				if strings.Split(*event.ResourceStatus, "_")[0] == c || c == "" {
					Log(strings.Trim(line, "- "), level.info)
				}

				printed[line] = nil
			}
		}

		// Sleep 2 seconds before next check
		time.Sleep(time.Duration(2 * time.Second))
	}
}

// all - returns true if all items in array the same as the given string
func all(a []string, s string) bool {<commit_msg>verbose function removed from helpers<commit_after>package commands

// -- Contains helper functions

import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"runtime"
	"strconv"
	"strings"
	"time"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/s3"
	"github.com/ttacon/chalk"
)

// configTemplate - Returns template byte string for init() function
func configTemplate(project string, region string) []byte {
	return []byte(fmt.Sprintf(`
# Specify the AWS region code
# qaz will attempt to get it from AWS configuration
# or from the environment. This setting overrides
# every other.

region: %s

# Required: specify the name of the Project
# (qaz will prepend this value to the stack
# names defined below.

project: %s

# Optional: global values accisible accross
# all stacks can be define under global

global:

# Stack-specific variables and
# arbitrary keys cab be defined here,
# Under the [stacks] key word,

stacks:
  # Note that the stack name must match the file name of the template file. The extension does not need to be specified.
  your_stack_name_here:
    cf:
      your_key/value_pairs_here:
`, region, project))
}

// colorMap - Used to map a particular color to a cf status phrase - returns lowercase strings in color.
func colorMap(s string) string {

	// If Windows, disable colorS
	if runtime.GOOS == "windows" {
		return s
	}

	v := strings.Split(s, "_")[len(strings.Split(s, "_"))-1]

	var result string

	switch v {
	case "COMPLETE":
		result = chalk.Green.Color(s)
	case "PROGRESS":
		result = chalk.Yellow.Color(s)
	case "FAILED":
		result = chalk.Red.Color(s)
	case "SKIPPED":
		result = chalk.Blue.Color(s)
	default:
		// Unidentified, just returns the same string
		return strings.ToLower(s)
	}
	return strings.ToLower(result)
}

// colorString - Returns colored string
func colorString(s string, color string) string {

	// If Windows, disable colorS
	if runtime.GOOS == "windows" {
		return s
	}

	var result string
	switch strings.ToLower(color) {
	case "green":
		result = chalk.Green.Color(s)
	case "yellow":
		result = chalk.Yellow.Color(s)
	case "red":
		result = chalk.Red.Color(s)
	case "magenta":
		result = chalk.Magenta.Color(s)
	default:
		// Unidentified, just returns the same string
		return s
	}

	return result
}

// all - returns true if all items in array the same as the given string
func all(a []string, s string) bool {
{'fraction_non_alphanumeric': 0.11819917276487432, 'fraction_numerical': 0.0011135857461024498, 'mean_word_length': 3.70936329588015, 'pattern_counts': {'":': 16, '<': 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': '7106792', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2061, 'n_words': 658}