<commit_before>package installer

import (
	"bufio"
	"encoding/json"
	"io"
	"os"
	"os/exec"
	"strings"
	"syscall"

	"github.com/itchio/butler/installer/loggerwriter"
	"github.com/itchio/wharf/state"
	"github.com/pkg/errors"
)

type Any map[string]interface{}

type RunSelfResult struct {
	ExitCode int
	Results  []Any
	Errors   []string
}

type OnResultFunc func(res Any)

type RunSelfParams struct {
	Consumer *state.Consumer
	Args     []string
	OnResult OnResultFunc
}

func RunSelf(params *RunSelfParams) (*RunSelfResult, error) {
	selfPath, err := os.Executable()
	if err != nil {
		return nil, errors.Wrap(err, "getting path to own binary")
	}

	consumer := params.Consumer
	args := params.Args

	consumer.Infof("→ Invoking self (we're at %s)", selfPath)
	consumer.Infof("  butler ::: %s", strings.Join(args, " ::: "))

	res := &RunSelfResult{
		Results: []Any{},
	}

	completeArgs := append([]string{"--json"}, args...)

	cmd := exec.Command(selfPath, completeArgs...)
	parser := newParserWriter(consumer, res, params.OnResult)
	cmd.Stdout = parser
	cmd.Stderr = loggerwriter.New(consumer, "err")

	err = cmd.Run()
	if len(res.Errors) > 0 {
		return nil, errors.New(res.Errors[0])
	}<commit_msg>When invoking self, print full path<commit_after>package installer

import (
	"bufio"
	"encoding/json"
	"io"
	"os"
	"os/exec"
	"strings"
	"syscall"

	"github.com/itchio/butler/installer/loggerwriter"
	"github.com/itchio/wharf/state"
	"github.com/pkg/errors"
)

type Any map[string]interface{}

type RunSelfResult struct {
	ExitCode int
	Results  []Any
	Errors   []string
}

type OnResultFunc func(res Any)

type RunSelfParams struct {
	Consumer *state.Consumer
	Args     []string
	OnResult OnResultFunc
}

func RunSelf(params *RunSelfParams) (*RunSelfResult, error) {
	selfPath, err := os.Executable()
	if err != nil {
		return nil, errors.Wrap(err, "getting path to own binary")
	}

	consumer := params.Consumer
	args := params.Args

	consumer.Infof("→ Invoking self (%s)", selfPath)
	consumer.Infof("  butler ::: %s", strings.Join(args, " ::: "))

	res := &RunSelfResult{
		Results: []Any{},
	}

	completeArgs := append([]string{"--json"}, args...)

	cmd := exec.Command(selfPath, completeArgs...)
	parser := newParserWriter(consumer, res, params.OnResult)
	cmd.Stdout = parser
	cmd.Stderr = loggerwriter.New(consumer, "err")

	err = cmd.Run()
	if len(res.Errors) > 0 {
		return nil, errors.New(res.Errors[0])
	}
{'fraction_non_alphanumeric': 0.1556935817805383, 'fraction_numerical': 0.0016563146997929607, 'mean_word_length': 4.3215859030837, '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': '3701154', 'n_tokens_mistral': 901, 'n_tokens_neox': 855, 'n_words': 201}