<commit_before>package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"os/exec"
	"path/filepath"
	"strings"

	"github.com/fatih/color"
)

// GitPodsRunner builds, runs, stops and restarts GitPods.
type GitPodsRunner struct {
	name    string
	env     []string
	cmd     *exec.Cmd
	restart chan bool
}

func NewGitPodsRunner(name string, env []string) *GitPodsRunner {
	return &GitPodsRunner{
		name:    name,
		env:     env,
		restart: make(chan bool, 16),
	}
}

func (r *GitPodsRunner) Name() string {
	return r.name
}

func (r *GitPodsRunner) Run() error {
	if err := r.Build(); err == nil {
		r.restart <- true
	}

	for {
		_, more := <-r.restart
		if more {
			if r.cmd != nil {
				r.Stop()
			}

			go func() {
				r.cmd = exec.Command("./dev/" + r.name)
				r.cmd.Env = r.env
				stdout, err := r.cmd.StdoutPipe()
				if err != nil {
					return
				}
				stderr, err := r.cmd.StderrPipe()
				if err != nil {
					return
				}

				multi := io.MultiReader(stdout, stderr)

				if r.cmd.Start() != nil {
					return
				}

				scanner := bufio.NewScanner(multi)

				for scanner.Scan() {
					fmt.Printf("%s\t%s\n", color.HiBlueString(r.name), scanner.Text())
				}

				if err = r.cmd.Wait(); err != nil {
					return
				}
			}()
		} else {
			return nil
		}
	}
}

func (r *GitPodsRunner) Stop() {
	if r.cmd == nil || r.cmd.Process == nil {
		return
	}
	r.cmd.Process.Kill()
}

func (r *GitPodsRunner) Build() error {
	cmd := exec.Command("go", "build", "-v", "-ldflags", "-w -extldflags '-static'", "-o", "./dev/"+r.name, "./cmd/"+r.name)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	fmt.Println(strings.Join(cmd.Args, " "))

	return cmd.Run()
}

func (r *GitPodsRunner) Restart() {
	r.restart <- true
}

func (r *GitPodsRunner) Shutdown() {
	close(r.restart)
	r.Stop()
}

// CaddyRunner runs caddy
type CaddyRunner struct {
	cmd *exec.Cmd
}

func (r *CaddyRunner) Run() error {
	r.cmd = exec.Command(filepath.Join(".", "dev", "caddy"), "-conf", "./dev/Caddyfile")
	stdout, err := r.cmd.StdoutPipe()
	if err != nil {
		return err
	}
	stderr, err := r.cmd.StderrPipe()
	if err != nil {
		return err
	}

	multi := io.MultiReader(stdout, stderr)

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

	scanner := bufio.NewScanner(multi)

	for scanner.Scan() {
		fmt.Printf("%s\t%s\n", color.HiBlueString("caddy"), scanner.Text())
	}

	return r.cmd.Wait()
}

func (r *CaddyRunner) Stop() {
	if r.cmd == nil || r.cmd.Process == nil {
		return
	}
	r.cmd.Process.Kill()
}
<commit_msg>Use make command to build Go binaries<commit_after>package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"os/exec"
	"path/filepath"
	"strings"

	"github.com/fatih/color"
)

// GitPodsRunner builds, runs, stops and restarts GitPods.
type GitPodsRunner struct {
	name    string
	env     []string
	cmd     *exec.Cmd
	restart chan bool
}

func NewGitPodsRunner(name string, env []string) *GitPodsRunner {
	return &GitPodsRunner{
		name:    name,
		env:     env,
		restart: make(chan bool, 16),
	}
}

func (r *GitPodsRunner) Name() string {
	return r.name
}

func (r *GitPodsRunner) Run() error {
	if err := r.Build(); err == nil {
		r.restart <- true
	}

	for {
		_, more := <-r.restart
		if more {
			if r.cmd != nil {
				r.Stop()
			}

			go func() {
				r.cmd = exec.Command("./dev/" + r.name)
				r.cmd.Env = r.env
				stdout, err := r.cmd.StdoutPipe()
				if err != nil {
					return
				}
				stderr, err := r.cmd.StderrPipe()
				if err != nil {
					return
				}

				multi := io.MultiReader(stdout, stderr)

				if r.cmd.Start() != nil {
					return
				}

				scanner := bufio.NewScanner(multi)

				for scanner.Scan() {
					fmt.Printf("%s\t%s\n", color.HiBlueString(r.name), scanner.Text())
				}

				if err = r.cmd.Wait(); err != nil {
					return
				}
			}()
		} else {
			return nil
		}
	}
}

func (r *GitPodsRunner) Stop() {
	if r.cmd == nil || r.cmd.Process == nil {
		return
	}
	r.cmd.Process.Kill()
}

func (r *GitPodsRunner) Build() error {
	cmd := exec.Command("make", "dev/"+r.name)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	fmt.Println(strings.Join(cmd.Args, " "))

	return cmd.Run()
}

func (r *GitPodsRunner) Restart() {
	r.restart <- true
}

func (r *GitPodsRunner) Shutdown() {
	close(r.restart)
	r.Stop()
}

// CaddyRunner runs caddy
type CaddyRunner struct {
	cmd *exec.Cmd
}

func (r *CaddyRunner) Run() error {
	r.cmd = exec.Command(filepath.Join(".", "dev", "caddy"), "-conf", "./dev/Caddyfile")
	stdout, err := r.cmd.StdoutPipe()
	if err != nil {
		return err
	}
	stderr, err := r.cmd.StderrPipe()
	if err != nil {
		return err
	}

	multi := io.MultiReader(stdout, stderr)

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

	scanner := bufio.NewScanner(multi)

	for scanner.Scan() {
		fmt.Printf("%s\t%s\n", color.HiBlueString("caddy"), scanner.Text())
	}

	return r.cmd.Wait()
}

func (r *CaddyRunner) Stop() {
	if r.cmd == nil || r.cmd.Process == nil {
		return
	}
	r.cmd.Process.Kill()
}

{'fraction_non_alphanumeric': 0.17733494363929148, 'fraction_numerical': 0.0008051529790660225, 'mean_word_length': 2.72768192048012, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2940703', 'n_tokens_mistral': 2260, 'n_tokens_neox': 1999, 'n_words': 460}