<commit_before>package config

import (
	"gitlab.com/rliebz/tusk/interp"
	"gitlab.com/rliebz/tusk/task"
	yaml "gopkg.in/yaml.v2"
)

// FindAllFlags returns a list of flags relevant for a given task.
func (cfg *Config) FindAllFlags(t *task.Task) ([]*task.Arg, error) {
	names, err := getDependencies(t)
	if err != nil {
		return nil, err
	}

	candidates := make(map[string]*task.Arg)
	for name, arg := range cfg.Args {
		arg.Name = name
		candidates[name] = arg
	}

	var required []*task.Arg
	for name, arg := range t.Args {
		arg.Name = name
		required = append(required, arg)
		candidates[name] = arg
	}

	required, err = recurseDependencies(names, candidates, required)
	if err != nil {
		return nil, err
	}

	return required, nil
}

func recurseDependencies(
	entry []string, candidates map[string]*task.Arg, found []*task.Arg,
) ([]*task.Arg, error) {

candidates:
	for _, item := range entry {
		candidate := candidates[item]
		for _, f := range found {
			if f == candidate {
				continue candidates
			}
		}

		found = append(found, candidate)
		dependencies, err := getDependencies(found)
		if err != nil {
			return nil, err
		}

		found, err = recurseDependencies(dependencies, candidates, found)
		if err != nil {
			return nil, err
		}
	}

	return found, nil
}

func getDependencies(item interface{}) ([]string, error) {

	marshalled, err := yaml.Marshal(item)
	if err != nil {<commit_msg>Skip interpolation when no arg is defined<commit_after>package config

import (
	"gitlab.com/rliebz/tusk/interp"
	"gitlab.com/rliebz/tusk/task"
	yaml "gopkg.in/yaml.v2"
)

// FindAllFlags returns a list of flags relevant for a given task.
func (cfg *Config) FindAllFlags(t *task.Task) ([]*task.Arg, error) {
	names, err := getDependencies(t)
	if err != nil {
		return nil, err
	}

	candidates := make(map[string]*task.Arg)
	for name, arg := range cfg.Args {
		arg.Name = name
		candidates[name] = arg
	}

	var required []*task.Arg
	for name, arg := range t.Args {
		arg.Name = name
		required = append(required, arg)
		candidates[name] = arg
	}

	required, err = recurseDependencies(names, candidates, required)
	if err != nil {
		return nil, err
	}

	return required, nil
}

func recurseDependencies(
	entry []string, candidates map[string]*task.Arg, found []*task.Arg,
) ([]*task.Arg, error) {

candidates:
	for _, item := range entry {
		candidate := candidates[item]

		if candidate == nil {
			continue
		}

		for _, f := range found {
			if f == candidate {
				continue candidates
			}
		}

		found = append(found, candidate)
		dependencies, err := getDependencies(found)
		if err != nil {
			return nil, err
		}

		found, err = recurseDependencies(dependencies, candidates, found)
		if err != nil {
			return nil, err
		}
	}

	return found, nil
}

func getDependencies(item interface{}) ([]string, error) {

	marshalled, err := yaml.Marshal(item)
	if err != nil {
{'fraction_non_alphanumeric': 0.133008356545961, 'fraction_numerical': 0.0006963788300835655, 'mean_word_length': 3.611556982343499, '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': '2811726', 'n_tokens_mistral': 1085, 'n_tokens_neox': 975, 'n_words': 284}