<commit_before>package main

import (
	"bufio"
	"errors"
	"log"
	"os"
	"os/exec"
	"strings"
)

type UbootEnvCommand struct {
	EnvCmd string
}

type UbootVars map[string]string

type Runner interface {
	Run(string, ...string) *exec.Cmd
}

type RealRunner struct{}

var (
	runner Runner
	Log    *log.Logger
)

func init() {
	runner = RealRunner{}
	Log = log.New(os.Stdout, "MESSAGE:", log.Ldate|log.Ltime|log.Lshortfile)
}

// the real runner for the actual program, actually execs the command
func (r RealRunner) Run(command string, args ...string) *exec.Cmd {
	return exec.Command(command, args...)
}

func (c *UbootEnvCommand) Command(params ...string) (UbootVars, error) {

	cmd := runner.Run(c.EnvCmd, params...)
	cmdReader, err := cmd.StdoutPipe()

	if err != nil {
		Log.Println("Error creating StdoutPipe:", err)
		return nil, err
	}

	scanner := bufio.NewScanner(cmdReader)

	err = cmd.Start()
	if err != nil {
		Log.Println("There was an error getting or setting U-Boot env")
		return nil, err
	}

	var env_variables = make(UbootVars)

	for scanner.Scan() {
		Log.Println("Have U-Boot variable:", scanner.Text())
		splited_line := strings.Split(scanner.Text(), "=")

		//we are having empty line (usually at the end of output)
		if scanner.Text() == "" {
			continue
		}

		//we have some malformed data or Warning/Error
		if len(splited_line) != 2 {
			Log.Println("U-Boot variable malformed or error occured")
			return nil, errors.New("Invalid U-Boot variable or error: " + scanner.Text())
		}

		env_variables[splited_line[0]] = splited_line[1]
	}

	err = cmd.Wait()
	if err != nil {
		Log.Println("U-Boot env command returned non zero status")
		return nil, err
	}

	if len(env_variables) > 0 {
		Log.Println("List of U-Boot variables:", env_variables)
	}

	return env_variables, err
}

func GetBootEnv(var_name ...string) (UbootVars, error) {
	get_env := UbootEnvCommand{"fw_printenv"}
	return get_env.Command(var_name...)
}

func SetBootEnv(var_name string, value string) error {

	set_env := UbootEnvCommand{"fw_setenv"}

	if _, err := set_env.Command(var_name, value); err != nil {
		Log.Println("Error setting U-Boot variable:", err)
		return err
	}
	return nil
}<commit_msg>Change name of local function to be not exported from module.<commit_after>package main

import (
	"bufio"
	"errors"
	"log"
	"os"
	"os/exec"
	"strings"
)

type UbootEnvCommand struct {
	EnvCmd string
}

type UbootVars map[string]string

type Runner interface {
	Run(string, ...string) *exec.Cmd
}

type RealRunner struct{}

var (
	runner Runner
	Log    *log.Logger
)

func init() {
	runner = RealRunner{}
	Log = log.New(os.Stdout, "BOOT_ENV:", log.Ldate|log.Ltime|log.Lshortfile)
}

// the real runner for the actual program, actually execs the command
func (r RealRunner) Run(command string, args ...string) *exec.Cmd {
	return exec.Command(command, args...)
}

func (c *UbootEnvCommand) command(params ...string) (UbootVars, error) {

	cmd := runner.Run(c.EnvCmd, params...)
	cmdReader, err := cmd.StdoutPipe()

	if err != nil {
		Log.Println("Error creating StdoutPipe:", err)
		return nil, err
	}

	scanner := bufio.NewScanner(cmdReader)

	err = cmd.Start()
	if err != nil {
		Log.Println("There was an error getting or setting U-Boot env")
		return nil, err
	}

	var env_variables = make(UbootVars)

	for scanner.Scan() {
		Log.Println("Have U-Boot variable:", scanner.Text())
		splited_line := strings.Split(scanner.Text(), "=")

		//we are having empty line (usually at the end of output)
		if scanner.Text() == "" {
			continue
		}

		//we have some malformed data or Warning/Error
		if len(splited_line) != 2 {
			Log.Println("U-Boot variable malformed or error occured")
			return nil, errors.New("Invalid U-Boot variable or error: " + scanner.Text())
		}

		env_variables[splited_line[0]] = splited_line[1]
	}

	err = cmd.Wait()
	if err != nil {
		Log.Println("U-Boot env command returned non zero status")
		return nil, err
	}

	if len(env_variables) > 0 {
		Log.Println("List of U-Boot variables:", env_variables)
	}

	return env_variables, err
}

func GetBootEnv(var_name ...string) (UbootVars, error) {
	get_env := UbootEnvCommand{"fw_printenv"}
	return get_env.command(var_name...)
}

func SetBootEnv(var_name string, value string) error {

	set_env := UbootEnvCommand{"fw_setenv"}

	if _, err := set_env.command(var_name, value); err != nil {
		Log.Println("Error setting U-Boot variable:", err)
		return err
	}
	return nil
}
{'fraction_non_alphanumeric': 0.13686583990980833, 'fraction_numerical': 0.0018038331454340473, 'mean_word_length': 3.8962472406181017, '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': '2075246', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1558, 'n_words': 434}