<commit_before>package cli

import (
	"fmt"
	"io"
	"os"

	"github.com/vektra/cypress/commands"
	"github.com/vektra/cypress/plugin"
)

type CatCommand struct {
	Kv     bool `short:"k" description:"display in key=value format"`
	Human  bool `short:"H" description:"display in easy to read format"`
	Json   bool `short:"j" description:"display in json"`
	Native bool `short:"n" description:"output as native binary"`
}

func (c *CatCommand) Execute(args []string) error {
	var cnt int

	if c.Kv {
		cnt++
	}

	if c.Human {
		cnt++
	}

	if c.Json {
		cnt++
	}

	if c.Native {
		cnt++
	}

	var format commands.Format

	switch {
	case cnt == 0:
		format = commands.KV
	case cnt > 1:
		return fmt.Errorf("multiple display types requested, only use one")
	case c.Kv:
		format = commands.KV
	case c.Human:
		format = commands.HUMAN
	case c.Json:
		format = commands.JSON
	case c.Native:
		format = commands.NATIVE
	}

	dir := args[0]
	if dir == "" {
		return fmt.Errorf("no source specified")
	}

	spool, err := plugin.NewSpool(dir)
	if err != nil {
		return err
	}

	gen, err := spool.Generator()
	if err != nil {
		return err
	}

	cat, err := commands.NewCat(os.Stdout, gen, format)
	if err != nil {
		return err
	}

	err = cat.Run()
	if err != nil {
		if err == io.EOF {
			return nil
		}

		return err
	}

	return nil
}

func init() {
	long := `Given a source of messages, the cat command will read those messages in and print them out. Commonly, users point cat at a spool directory to read the message contained within.`

	addCommand("cat", "display messages", long, &CatCommand{})
}<commit_msg>Change cat to decode the stream on stdin<commit_after>package cli

import (
	"fmt"
	"io"
	"os"

	"github.com/vektra/cypress"
	"github.com/vektra/cypress/commands"
)

type CatCommand struct {
	Kv     bool `short:"k" description:"display in key=value format"`
	Human  bool `short:"H" description:"display in easy to read format"`
	Json   bool `short:"j" description:"display in json"`
	Native bool `short:"n" description:"output as native binary"`
}

func (c *CatCommand) Execute(args []string) error {
	var cnt int

	if c.Kv {
		cnt++
	}

	if c.Human {
		cnt++
	}

	if c.Json {
		cnt++
	}

	if c.Native {
		cnt++
	}

	var format commands.Format

	switch {
	case cnt == 0:
		format = commands.KV
	case cnt > 1:
		return fmt.Errorf("multiple display types requested, only use one")
	case c.Kv:
		format = commands.KV
	case c.Human:
		format = commands.HUMAN
	case c.Json:
		format = commands.JSON
	case c.Native:
		format = commands.NATIVE
	}

	dec, err := cypress.NewStreamDecoder(os.Stdin)
	if err != nil {
		return err
	}

	cat, err := commands.NewCat(os.Stdout, dec, format)
	if err != nil {
		return err
	}

	err = cat.Run()
	if err != nil {
		if err == io.EOF {
			return nil
		}

		return err
	}

	return nil
}

func init() {
	long := `Given a stream on stdin, the cat command will read those messages in and print them out.`

	addCommand("cat", "display messages", long, &CatCommand{})
}
{'fraction_non_alphanumeric': 0.12768096514745308, 'fraction_numerical': 0.001675603217158177, 'mean_word_length': 3.2642857142857142, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3563333', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1075, 'n_words': 345}