<commit_before>package util

import (
	"bytes"
	"io/ioutil"
	"os"
	"os/exec"
	"syscall"

	"github.com/fatih/color"
)

const defaultFailedCode = 1

// Set up the output streams (and colors) to stream command output if verbose is configured
func StreamCommand(cmd *exec.Cmd) error {
	return RunCommand(cmd, false)
}

// Set up the output streams (and colors) to stream command output regardless of verbosity
func ForceStreamCommand(cmd *exec.Cmd) error {
	return RunCommand(cmd, true)
}

// Run the command
func RunCommand(cmd *exec.Cmd, forceOutput bool) error {
	cmd.Stderr = os.Stderr
	if Logger().IsVerbose || forceOutput {
		cmd.Stdout = os.Stdout
	} else {
		cmd.Stdout = ioutil.Discard
	}

	color.Set(color.FgCyan)
	err := cmd.Run()
	color.Unset()
	return err
}

// This is similar to ForceStreamCommand in that it will issue all output
// regardless of verbose mode. Further, this version of the command captures the
// exit status of any executed command. This function is intended to simulate
// native execution of the command passed to it.
//
// @todo streaming the output instead of buffering until completion.
func PassthruCommand(cmd *exec.Cmd) (stdout string, stderr string, exitCode int) {
	var outbuf, errbuf bytes.Buffer

	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout

	err := cmd.Run()
	stdout = outbuf.String()
	stderr = errbuf.String()

	if err != nil {
		// Try to get the exit code.
		if exitError, ok := err.(*exec.ExitError); ok {
			ws := exitError.Sys().(syscall.WaitStatus)
			exitCode = ws.ExitStatus()
		} else {<commit_msg>Enable running interactive commands such as cli container.<commit_after>package util

import (
	"bytes"
	"io/ioutil"
	"os"
	"os/exec"
	"syscall"

	"github.com/fatih/color"
)

const defaultFailedCode = 1

// Set up the output streams (and colors) to stream command output if verbose is configured
func StreamCommand(cmd *exec.Cmd) error {
	return RunCommand(cmd, false)
}

// Set up the output streams (and colors) to stream command output regardless of verbosity
func ForceStreamCommand(cmd *exec.Cmd) error {
	return RunCommand(cmd, true)
}

// Run the command
func RunCommand(cmd *exec.Cmd, forceOutput bool) error {
	cmd.Stderr = os.Stderr
	if Logger().IsVerbose || forceOutput {
		cmd.Stdout = os.Stdout
	} else {
		cmd.Stdout = ioutil.Discard
	}

	color.Set(color.FgCyan)
	err := cmd.Run()
	color.Unset()
	return err
}

// This is similar to ForceStreamCommand in that it will issue all output
// regardless of verbose mode. Further, this version of the command captures the
// exit status of any executed command. This function is intended to simulate
// native execution of the command passed to it.
//
// @todo streaming the output instead of buffering until completion.
func PassthruCommand(cmd *exec.Cmd) (stdout string, stderr string, exitCode int) {
	var outbuf, errbuf bytes.Buffer

	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
        cmd.Stdin = os.Stdin

	err := cmd.Run()
	stdout = outbuf.String()
	stderr = errbuf.String()

	if err != nil {
		// Try to get the exit code.
		if exitError, ok := err.(*exec.ExitError); ok {
			ws := exitError.Sys().(syscall.WaitStatus)
			exitCode = ws.ExitStatus()
		} else {
{'fraction_non_alphanumeric': 0.10615577889447236, 'fraction_numerical': 0.000628140703517588, 'mean_word_length': 3.7395833333333335, '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': '6113901', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1015, 'n_words': 359}