<commit_before>package cloudcfg

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"strings"
	"text/tabwriter"

	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
	"gopkg.in/v1/yaml"
)

type ResourcePrinter interface {
	Print(string, io.Writer) error
}

type IdentityPrinter struct{}

func (i *IdentityPrinter) Print(data string, w io.Writer) error {
	_, err := io.Copy(w, bytes.NewBufferString(data))
	return err
}

type YAMLPrinter struct{}

func (y *YAMLPrinter) Print(data string, w io.Writer) error {
	var obj interface{}
	if err := json.Unmarshal([]byte(data), &obj); err != nil {
		return err
	}
	output, err := yaml.Marshal(obj)
	if err != nil {
		return err
	}
	_, err = fmt.Fprint(w, string(output))
	return err
}

type HumanReadablePrinter struct{}

var taskColumns = []string{"Name", "Image(s)", "Host", "Labels"}
var replicationControllerColumns = []string{"Name", "Image(s)", "Label Query", "Replicas"}
var serviceColumns = []string{"Name", "Label Query", "Port"}

func (h *HumanReadablePrinter) unknown(data string, w io.Writer) error {
	_, err := fmt.Fprintf(w, "Unknown object: %s", data)
	return err
}

func (h *HumanReadablePrinter) printHeader(columnNames []string, w io.Writer) error {
	if _, err := fmt.Fprintf(w, "%s\n", strings.Join(columnNames, "\t")); err != nil {
		return err
	}
	var lines []string
	for _, _ = range columnNames {
		lines = append(lines, "----------")<commit_msg>Add some more docs.<commit_after>package cloudcfg

import (
	"encoding/json"
	"fmt"
	"io"
	"strings"
	"text/tabwriter"

	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
	"gopkg.in/v1/yaml"
)

// ResourcePrinter is an interface that knows how to print API resources
type ResourcePrinter interface {
	// Print receives an arbitrary JSON body, formats it and prints it to a writer
	Print(string, io.Writer) error
}

// Identity printer simply copies the body out to the output stream
type IdentityPrinter struct{}

func (i *IdentityPrinter) Print(data string, w io.Writer) error {
	_, err := fmt.Fprint(w, data)
	return err
}

// YAMLPrinter parses JSON, and re-formats as YAML
type YAMLPrinter struct{}

func (y *YAMLPrinter) Print(data string, w io.Writer) error {
	var obj interface{}
	if err := json.Unmarshal([]byte(data), &obj); err != nil {
		return err
	}
	output, err := yaml.Marshal(obj)
	if err != nil {
		return err
	}
	_, err = fmt.Fprint(w, string(output))
	return err
}

// HumanReadablePrinter attempts to provide more elegant output
type HumanReadablePrinter struct{}

var taskColumns = []string{"Name", "Image(s)", "Host", "Labels"}
var replicationControllerColumns = []string{"Name", "Image(s)", "Label Query", "Replicas"}
var serviceColumns = []string{"Name", "Label Query", "Port"}

func (h *HumanReadablePrinter) unknown(data string, w io.Writer) error {
	_, err := fmt.Fprintf(w, "Unknown object: %s", data)
	return err
}

func (h *HumanReadablePrinter) printHeader(columnNames []string, w io.Writer) error {
	if _, err := fmt.Fprintf(w, "%s\n", strings.Join(columnNames, "\t")); err != nil {
		return err
	}
	var lines []string
	for _, _ = range columnNames {
		lines = append(lines, "----------")
{'fraction_non_alphanumeric': 0.15106994570424784, 'fraction_numerical': 0.0006387735547748323, 'mean_word_length': 4.523809523809524, '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': '5694699', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1048, 'n_words': 316}