<commit_before>package director

import (
	"bufio"
	"fmt"
	"io"
	"os/exec"
	"strings"
)

var defaultBoshArgs = []string{"--non-interactive", "--tty", "--no-color"}

// RunAuthenticatedCommand runs a command against the bosh director, after authenticating
func (client *Client) RunAuthenticatedCommand(stdout, stderr io.Writer, detach bool, args ...string) error {
	args = append([]string{
		"--environment",
		fmt.Sprintf("https://%s", client.creds.Host),
		"--ca-cert",
		client.caCertPath,
		"--client",
		client.creds.Username,
		"--client-secret",
		client.creds.Password,
	}, args...)

	if detach {
		return client.runDetachingCommand(stdout, stderr, args...)
	}

	return client.RunCommand(stdout, stderr, args...)
}

// RunCommand runs a command against the bosh director
// https://github.com/cloudfoundry/bosh-cli/blob/master/main.go
func (client *Client) RunCommand(stdout, stderr io.Writer, args ...string) error {
	if err := client.ensureBinaryDownloaded(); err != nil {
		return err
	}

	args = append(defaultBoshArgs, args...)

	cmd := exec.Command(client.tempDir.Path("bosh-cli"), args...)
	cmd.Stdout = stdout
	cmd.Stderr = stderr
	return cmd.Run()
}

func (client *Client) runDetachingCommand(stdout, stderr io.Writer, args ...string) error {
	if err := client.ensureBinaryDownloaded(); err != nil {
		return err
	}

	args = append(defaultBoshArgs, args...)

	cmd := exec.Command(client.tempDir.Path("bosh-cli"), args...)
	cmd.Stderr = stderr

	cmdReader, err := cmd.StdoutPipe()
	if err != nil {
		return err
	}

	scanner := bufio.NewScanner(cmdReader)

	if err := cmd.Start(); err != nil {
		return err
	}

	for scanner.Scan() {
		text := scanner.Text()
		if err := stdout.Write([]byte(fmt.Sprintf("%s\n", text))); err != nil {
			return err
		}
		if strings.HasPrefix(text, "Task") {
			stdout.Write([]byte("Task started, detaching output\n"))
			return nil
		}
	}

	return fmt.Errorf("Didn't detect successful task start in BOSH comand: bosh-cli %s", strings.Join(args, " "))
}
<commit_msg>fix issue with called Write<commit_after>package director

import (
	"bufio"
	"fmt"
	"io"
	"os/exec"
	"strings"
)

var defaultBoshArgs = []string{"--non-interactive", "--tty", "--no-color"}

// RunAuthenticatedCommand runs a command against the bosh director, after authenticating
func (client *Client) RunAuthenticatedCommand(stdout, stderr io.Writer, detach bool, args ...string) error {
	args = append([]string{
		"--environment",
		fmt.Sprintf("https://%s", client.creds.Host),
		"--ca-cert",
		client.caCertPath,
		"--client",
		client.creds.Username,
		"--client-secret",
		client.creds.Password,
	}, args...)

	if detach {
		return client.runDetachingCommand(stdout, stderr, args...)
	}

	return client.RunCommand(stdout, stderr, args...)
}

// RunCommand runs a command against the bosh director
// https://github.com/cloudfoundry/bosh-cli/blob/master/main.go
func (client *Client) RunCommand(stdout, stderr io.Writer, args ...string) error {
	if err := client.ensureBinaryDownloaded(); err != nil {
		return err
	}

	args = append(defaultBoshArgs, args...)

	cmd := exec.Command(client.tempDir.Path("bosh-cli"), args...)
	cmd.Stdout = stdout
	cmd.Stderr = stderr
	return cmd.Run()
}

func (client *Client) runDetachingCommand(stdout, stderr io.Writer, args ...string) error {
	if err := client.ensureBinaryDownloaded(); err != nil {
		return err
	}

	args = append(defaultBoshArgs, args...)

	cmd := exec.Command(client.tempDir.Path("bosh-cli"), args...)
	cmd.Stderr = stderr

	cmdReader, err := cmd.StdoutPipe()
	if err != nil {
		return err
	}

	scanner := bufio.NewScanner(cmdReader)

	if err := cmd.Start(); err != nil {
		return err
	}

	for scanner.Scan() {
		text := scanner.Text()
		if _, err := stdout.Write([]byte(fmt.Sprintf("%s\n", text))); err != nil {
			return err
		}
		if strings.HasPrefix(text, "Task") {
			stdout.Write([]byte("Task started, detaching output\n"))
			return nil
		}
	}

	return fmt.Errorf("Didn't detect successful task start in BOSH comand: bosh-cli %s", strings.Join(args, " "))
}

{'fraction_non_alphanumeric': 0.16571711667079514, 'fraction_numerical': 0.0, 'mean_word_length': 3.795724465558195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1158919', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1353, 'n_words': 338}