<commit_before>package models

import "fmt"

type Recipe struct {
	Name       string
	Attributes []string
	Actions    []Command
}

func (recipe Recipe) Execute() {
	fmt.Printf("\nExecuting recipe '%s'\n", recipe.Name)
	for i, action := range recipe.Actions {
		err := action.Execute(recipe, i+1)
		if err != nil {
			fmt.Printf("ERROR executing action #%d of recipe '%s': %s\n", i, recipe.Name, err)
			return
		}
	}
	return
}

func (recipe *Recipe) AddAction(action Command) {
	recipe.Actions = append(recipe.Actions, action)
}

func (recipe *Recipe) ActionNames() []string {
	var actions []string
	for _, a := range recipe.Actions {
		if a != nil && a.GetName() != "" {<commit_msg>Filter recipes by host, OS and disabled attributes<commit_after>package models

import (
	"fmt"
	"os"
	"runtime"
	"strings"

	"github.com/dpecos/dotback/utils"
)

type Recipe struct {
	Name       string
	Attributes []string
	Actions    []Command
}

func (recipe Recipe) Execute() {
	if ex, reason := recipe.shouldExecute(); !ex {
		fmt.Printf("\nRecipe '%s' not being executed: %s\n", recipe.Name, reason)
		return
	}
	fmt.Printf("\nExecuting recipe '%s'\n", recipe.Name)
	for i, action := range recipe.Actions {
		err := action.Execute(recipe, i+1)
		if err != nil {
			fmt.Printf("ERROR executing action #%d of recipe '%s': %s\n", i, recipe.Name, err)
			return
		}
	}
	return
}

func (recipe *Recipe) shouldExecute() (bool, string) {
	for _, attr := range recipe.Attributes {
		if attr == "disabled" {
			return false, "Recipe disabled"
		}

		host, err := os.Hostname()
		utils.CheckError("Could not retrieve host name", err)

		if ok, reason := check(attr, "host", host); !ok {
			return false, reason
		}

		goos := runtime.GOOS
		if ok, reason := check(attr, "os", goos); !ok {
			return false, reason
		}
	}

	return true, ""
}

func check(attr, param, value string) (bool, string) {
	if strings.HasPrefix(attr, param+"=") {
		if strings.HasSuffix(attr, "=!"+value) {
			return false, param + " excluded (" + value + "): " + attr
		}
		if !strings.Contains(attr, "=!") && !strings.HasSuffix(attr, "="+value) {
			return false, param + " does not match (" + value + "): " + attr
		}
	}

	return true, ""
}

func (recipe *Recipe) AddAction(action Command) {
	recipe.Actions = append(recipe.Actions, action)
}

func (recipe *Recipe) ActionNames() []string {
	var actions []string
	for _, a := range recipe.Actions {
		if a != nil && a.GetName() != "" {
{'fraction_non_alphanumeric': 0.16229508196721312, 'fraction_numerical': 0.000819672131147541, 'mean_word_length': 3.640684410646388, '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': '3168951', 'n_tokens_mistral': 900, 'n_tokens_neox': 856, 'n_words': 246}