<commit_before>package main

// Script Functionality

import (
	"fmt"
	"github.com/spf13/cobra"
	"github.com/stroblindustries/coreutils"
	"os"
	"path/filepath"
	"strings"
)

var scriptCmd = &cobra.Command{
	Use:     "script",
	Aliases: []string{"run-script"},
	Short:   "Run a custom script",
	Long:    "Run a custom script",
	Run:     script,
}

var verbose bool

func init() {
	scriptCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose mode.")
}

func script(cmd *cobra.Command, args []string) {
	if len(args) != 0 { // If no argument are passed
		for _, arg := range args { // For each argument
			if _, exists := noodles.Scripts[arg]; exists { // If this
				RunScript(arg)
			} else {
				fmt.Printf("%s is not a valid script. Exiting.\n", arg)
				break
			}
		}
	} else {
		if len(noodles.Scripts) != 0 { // If there are scripts set
			fmt.Printf("No scripts passed to run. Here is a list:\n\n")
			for name, script := range noodles.Scripts {
				line := name

				if script.Description != "" {
					line += ": " + script.Description
				}

				fmt.Println("-", line)
			}
			fmt.Printf("\n") // Intentional padding ad end of output
		} else {
			fmt.Println("No scripts defined in your noodles.toml file.")
		}
	}
}

// RunScript will run the script provided
func RunScript(name string) {
	script, _ := noodles.Scripts[name] // Get our script

	if script.Exec != "" { // If there is an executable
		if script.Directory != "" { // If we should run this command in a directory
			failedToChange := os.Chdir(filepath.Join(workdir, script.Directory)) // Change to the directory

			if failedToChange != nil { // If we failed to change to the directory
				fmt.Printf("Failed to change to the following directory: %s\n", script.Directory)

				if verbose {
					fmt.Printf("Full error: %s\n", failedToChange)
				}

				return // Don't continue with exec
			}
		}

		if verbose {<commit_msg>Simplify script primary func and support -s / --script arg.<commit_after>package main

// Script Functionality

import (
	"fmt"
	"github.com/spf13/cobra"
	"github.com/stroblindustries/coreutils"
	"os"
	"path/filepath"
	"strings"
)

var scriptCmd = &cobra.Command{
	Use:     "script",
	Aliases: []string{"run-script"},
	Short:   "Run a custom script",
	Long:    "Run a custom script",
	Run:     script,
}

var verbose bool
var selectedScript string

func init() {
	scriptCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose mode.")
	scriptCmd.Flags().StringVarP(&selectedScript, "script", "s", "", "Name of the script we're running")
}

func script(cmd *cobra.Command, args []string) {
	if selectedScript == "" { // If no script is set
		for name := range noodles.Scripts {
			RunScript(name)
		}
	} else { // If a script is set
		RunScript(selectedScript)
	}
}

// RunScript will run the script provided
func RunScript(name string) {
	script, _ := noodles.Scripts[name] // Get our script

	if script.Exec != "" { // If there is an executable
		if script.Directory != "" { // If we should run this command in a directory
			failedToChange := os.Chdir(filepath.Join(workdir, script.Directory)) // Change to the directory

			if failedToChange != nil { // If we failed to change to the directory
				fmt.Printf("Failed to change to the following directory: %s\n", script.Directory)

				if verbose {
					fmt.Printf("Full error: %s\n", failedToChange)
				}

				return // Don't continue with exec
			}
		}

		if verbose {
{'fraction_non_alphanumeric': 0.1357308584686775, 'fraction_numerical': 0.0017401392111368909, 'mean_word_length': 3.17049576783555, 'pattern_counts': {'":': 1, '<': 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': '1647565', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1110, 'n_words': 355}