Rework modifiers to variables again
This commit is contained in:
@@ -16,18 +16,17 @@ import (
|
||||
var modifyCommandLogger = logger.Default.WithPrefix("utils/modifycommand")
|
||||
|
||||
type ModifyCommand struct {
|
||||
Name string `yaml:"name,omitempty" toml:"name,omitempty"`
|
||||
Regex string `yaml:"regex,omitempty" toml:"regex,omitempty"`
|
||||
Regexes []string `yaml:"regexes,omitempty" toml:"regexes,omitempty"`
|
||||
Lua string `yaml:"lua,omitempty" toml:"lua,omitempty"`
|
||||
Files []string `yaml:"files,omitempty" toml:"files,omitempty"`
|
||||
Reset bool `yaml:"reset,omitempty" toml:"reset,omitempty"`
|
||||
LogLevel string `yaml:"loglevel,omitempty" toml:"loglevel,omitempty"`
|
||||
Isolate bool `yaml:"isolate,omitempty" toml:"isolate,omitempty"`
|
||||
NoDedup bool `yaml:"nodedup,omitempty" toml:"nodedup,omitempty"`
|
||||
Disabled bool `yaml:"disable,omitempty" toml:"disable,omitempty"`
|
||||
JSON bool `yaml:"json,omitempty" toml:"json,omitempty"`
|
||||
Modifiers map[string]interface{} `yaml:"modifiers,omitempty" toml:"modifiers,omitempty"`
|
||||
Name string `yaml:"name,omitempty" toml:"name,omitempty"`
|
||||
Regex string `yaml:"regex,omitempty" toml:"regex,omitempty"`
|
||||
Regexes []string `yaml:"regexes,omitempty" toml:"regexes,omitempty"`
|
||||
Lua string `yaml:"lua,omitempty" toml:"lua,omitempty"`
|
||||
Files []string `yaml:"files,omitempty" toml:"files,omitempty"`
|
||||
Reset bool `yaml:"reset,omitempty" toml:"reset,omitempty"`
|
||||
LogLevel string `yaml:"loglevel,omitempty" toml:"loglevel,omitempty"`
|
||||
Isolate bool `yaml:"isolate,omitempty" toml:"isolate,omitempty"`
|
||||
NoDedup bool `yaml:"nodedup,omitempty" toml:"nodedup,omitempty"`
|
||||
Disabled bool `yaml:"disable,omitempty" toml:"disable,omitempty"`
|
||||
JSON bool `yaml:"json,omitempty" toml:"json,omitempty"`
|
||||
}
|
||||
|
||||
type CookFile []ModifyCommand
|
||||
@@ -268,33 +267,36 @@ func LoadCommands(args []string) ([]ModifyCommand, map[string]interface{}, error
|
||||
loadCommandsLogger.Debug("Loading commands from arguments (cook files or direct patterns)")
|
||||
loadCommandsLogger.Trace("Input arguments: %v", args)
|
||||
commands := []ModifyCommand{}
|
||||
modifiers := make(map[string]interface{})
|
||||
variables := make(map[string]interface{})
|
||||
|
||||
for _, arg := range args {
|
||||
loadCommandsLogger.Debug("Processing argument for commands: %q", arg)
|
||||
var newCommands []ModifyCommand
|
||||
var newModifiers map[string]interface{}
|
||||
var newVariables map[string]interface{}
|
||||
var err error
|
||||
|
||||
// Check file extension to determine format
|
||||
if strings.HasSuffix(arg, ".toml") {
|
||||
loadCommandsLogger.Debug("Loading TOML commands from %q", arg)
|
||||
newCommands, newModifiers, err = LoadCommandsFromTomlFiles(arg)
|
||||
newCommands, newVariables, err = LoadCommandsFromTomlFiles(arg)
|
||||
if err != nil {
|
||||
loadCommandsLogger.Error("Failed to load TOML commands from argument %q: %v", arg, err)
|
||||
return nil, nil, fmt.Errorf("failed to load commands from TOML files: %w", err)
|
||||
}
|
||||
for k, v := range newModifiers {
|
||||
modifiers[k] = v
|
||||
for k, v := range newVariables {
|
||||
variables[k] = v
|
||||
}
|
||||
} else {
|
||||
// Default to YAML for .yml, .yaml, or any other extension
|
||||
loadCommandsLogger.Debug("Loading YAML commands from %q", arg)
|
||||
newCommands, err = LoadCommandsFromCookFiles(arg)
|
||||
newCommands, newVariables, err = LoadCommandsFromCookFiles(arg)
|
||||
if err != nil {
|
||||
loadCommandsLogger.Error("Failed to load YAML commands from argument %q: %v", arg, err)
|
||||
return nil, nil, fmt.Errorf("failed to load commands from cook files: %w", err)
|
||||
}
|
||||
for k, v := range newVariables {
|
||||
variables[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
loadCommandsLogger.Debug("Successfully loaded %d commands from %q", len(newCommands), arg)
|
||||
@@ -308,20 +310,21 @@ func LoadCommands(args []string) ([]ModifyCommand, map[string]interface{}, error
|
||||
}
|
||||
}
|
||||
|
||||
loadCommandsLogger.Info("Finished loading commands. Total %d commands and %d modifiers loaded", len(commands), len(modifiers))
|
||||
return commands, modifiers, nil
|
||||
loadCommandsLogger.Info("Finished loading commands. Total %d commands and %d variables loaded", len(commands), len(variables))
|
||||
return commands, variables, nil
|
||||
}
|
||||
|
||||
func LoadCommandsFromCookFiles(pattern string) ([]ModifyCommand, error) {
|
||||
func LoadCommandsFromCookFiles(pattern string) ([]ModifyCommand, map[string]interface{}, error) {
|
||||
loadCookFilesLogger := modifyCommandLogger.WithPrefix("LoadCommandsFromCookFiles").WithField("pattern", pattern)
|
||||
loadCookFilesLogger.Debug("Loading commands from cook files based on pattern")
|
||||
loadCookFilesLogger.Trace("Input pattern: %q", pattern)
|
||||
static, pattern := SplitPattern(pattern)
|
||||
commands := []ModifyCommand{}
|
||||
variables := make(map[string]interface{})
|
||||
cookFiles, err := doublestar.Glob(os.DirFS(static), pattern)
|
||||
if err != nil {
|
||||
loadCookFilesLogger.Error("Failed to glob cook files for pattern %q: %v", pattern, err)
|
||||
return nil, fmt.Errorf("failed to glob cook files: %w", err)
|
||||
return nil, nil, fmt.Errorf("failed to glob cook files: %w", err)
|
||||
}
|
||||
loadCookFilesLogger.Debug("Found %d cook files for pattern %q", len(cookFiles), pattern)
|
||||
loadCookFilesLogger.Trace("Cook files found: %v", cookFiles)
|
||||
@@ -334,35 +337,44 @@ func LoadCommandsFromCookFiles(pattern string) ([]ModifyCommand, error) {
|
||||
cookFileData, err := os.ReadFile(cookFile)
|
||||
if err != nil {
|
||||
loadCookFilesLogger.Error("Failed to read cook file %q: %v", cookFile, err)
|
||||
return nil, fmt.Errorf("failed to read cook file: %w", err)
|
||||
return nil, nil, fmt.Errorf("failed to read cook file: %w", err)
|
||||
}
|
||||
loadCookFilesLogger.Trace("Read %d bytes from cook file %q", len(cookFileData), cookFile)
|
||||
newCommands, err := LoadCommandsFromCookFile(cookFileData)
|
||||
newCommands, newVariables, err := LoadCommandsFromCookFile(cookFileData)
|
||||
if err != nil {
|
||||
loadCookFilesLogger.Error("Failed to load commands from cook file data for %q: %v", cookFile, err)
|
||||
return nil, fmt.Errorf("failed to load commands from cook file: %w", err)
|
||||
return nil, nil, fmt.Errorf("failed to load commands from cook file: %w", err)
|
||||
}
|
||||
commands = append(commands, newCommands...)
|
||||
loadCookFilesLogger.Debug("Added %d commands from cook file %q. Total commands now: %d", len(newCommands), cookFile, len(commands))
|
||||
for k, v := range newVariables {
|
||||
variables[k] = v
|
||||
}
|
||||
loadCookFilesLogger.Debug("Added %d commands and %d variables from cook file %q. Total commands now: %d", len(newCommands), len(newVariables), cookFile, len(commands))
|
||||
}
|
||||
|
||||
loadCookFilesLogger.Debug("Finished loading commands from cook files. Total %d commands", len(commands))
|
||||
return commands, nil
|
||||
loadCookFilesLogger.Debug("Finished loading commands from cook files. Total %d commands and %d variables", len(commands), len(variables))
|
||||
return commands, variables, nil
|
||||
}
|
||||
|
||||
func LoadCommandsFromCookFile(cookFileData []byte) ([]ModifyCommand, error) {
|
||||
func LoadCommandsFromCookFile(cookFileData []byte) ([]ModifyCommand, map[string]interface{}, error) {
|
||||
loadCommandLogger := modifyCommandLogger.WithPrefix("LoadCommandsFromCookFile")
|
||||
loadCommandLogger.Debug("Unmarshaling commands from cook file data")
|
||||
loadCommandLogger.Trace("Cook file data length: %d", len(cookFileData))
|
||||
commands := []ModifyCommand{}
|
||||
err := yaml.Unmarshal(cookFileData, &commands)
|
||||
|
||||
var cookFile struct {
|
||||
Variables map[string]interface{} `yaml:"variables,omitempty"`
|
||||
Commands []ModifyCommand `yaml:"commands"`
|
||||
}
|
||||
|
||||
err := yaml.Unmarshal(cookFileData, &cookFile)
|
||||
if err != nil {
|
||||
loadCommandLogger.Error("Failed to unmarshal cook file data: %v", err)
|
||||
return nil, fmt.Errorf("failed to unmarshal cook file: %w", err)
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal cook file: %w", err)
|
||||
}
|
||||
loadCommandLogger.Debug("Successfully unmarshaled %d commands", len(commands))
|
||||
loadCommandLogger.Trace("Unmarshaled commands: %v", commands)
|
||||
return commands, nil
|
||||
loadCommandLogger.Debug("Successfully unmarshaled %d commands and %d variables", len(cookFile.Commands), len(cookFile.Variables))
|
||||
loadCommandLogger.Trace("Unmarshaled commands: %v", cookFile.Commands)
|
||||
loadCommandLogger.Trace("Unmarshaled variables: %v", cookFile.Variables)
|
||||
return cookFile.Commands, cookFile.Variables, nil
|
||||
}
|
||||
|
||||
// CountGlobsBeforeDedup counts the total number of glob patterns across all commands before deduplication
|
||||
@@ -406,7 +418,7 @@ func LoadCommandsFromTomlFiles(pattern string) ([]ModifyCommand, map[string]inte
|
||||
loadTomlFilesLogger.Trace("Input pattern: %q", pattern)
|
||||
static, pattern := SplitPattern(pattern)
|
||||
commands := []ModifyCommand{}
|
||||
modifiers := make(map[string]interface{})
|
||||
variables := make(map[string]interface{})
|
||||
tomlFiles, err := doublestar.Glob(os.DirFS(static), pattern)
|
||||
if err != nil {
|
||||
loadTomlFilesLogger.Error("Failed to glob TOML files for pattern %q: %v", pattern, err)
|
||||
@@ -426,20 +438,20 @@ func LoadCommandsFromTomlFiles(pattern string) ([]ModifyCommand, map[string]inte
|
||||
return nil, nil, fmt.Errorf("failed to read TOML file: %w", err)
|
||||
}
|
||||
loadTomlFilesLogger.Trace("Read %d bytes from TOML file %q", len(tomlFileData), tomlFile)
|
||||
newCommands, newModifiers, err := LoadCommandsFromTomlFile(tomlFileData)
|
||||
newCommands, newVariables, err := LoadCommandsFromTomlFile(tomlFileData)
|
||||
if err != nil {
|
||||
loadTomlFilesLogger.Error("Failed to load commands from TOML file data for %q: %v", tomlFile, err)
|
||||
return nil, nil, fmt.Errorf("failed to load commands from TOML file: %w", err)
|
||||
}
|
||||
commands = append(commands, newCommands...)
|
||||
for k, v := range newModifiers {
|
||||
modifiers[k] = v
|
||||
for k, v := range newVariables {
|
||||
variables[k] = v
|
||||
}
|
||||
loadTomlFilesLogger.Debug("Added %d commands and %d modifiers from TOML file %q. Total commands now: %d", len(newCommands), len(newModifiers), tomlFile, len(commands))
|
||||
loadTomlFilesLogger.Debug("Added %d commands and %d variables from TOML file %q. Total commands now: %d", len(newCommands), len(newVariables), tomlFile, len(commands))
|
||||
}
|
||||
|
||||
loadTomlFilesLogger.Debug("Finished loading commands from TOML files. Total %d commands and %d modifiers", len(commands), len(modifiers))
|
||||
return commands, modifiers, nil
|
||||
loadTomlFilesLogger.Debug("Finished loading commands from TOML files. Total %d commands and %d variables", len(commands), len(variables))
|
||||
return commands, variables, nil
|
||||
}
|
||||
|
||||
func LoadCommandsFromTomlFile(tomlFileData []byte) ([]ModifyCommand, map[string]interface{}, error) {
|
||||
@@ -447,9 +459,9 @@ func LoadCommandsFromTomlFile(tomlFileData []byte) ([]ModifyCommand, map[string]
|
||||
loadTomlCommandLogger.Debug("Unmarshaling commands from TOML file data")
|
||||
loadTomlCommandLogger.Trace("TOML file data length: %d", len(tomlFileData))
|
||||
|
||||
// TOML structure for commands array and top-level modifiers
|
||||
// TOML structure for commands array and top-level variables
|
||||
var tomlData struct {
|
||||
Modifiers map[string]interface{} `toml:"modifiers,omitempty"`
|
||||
Variables map[string]interface{} `toml:"variables,omitempty"`
|
||||
Commands []ModifyCommand `toml:"commands"`
|
||||
// Also support direct array without wrapper
|
||||
DirectCommands []ModifyCommand `toml:"-"`
|
||||
@@ -463,13 +475,13 @@ func LoadCommandsFromTomlFile(tomlFileData []byte) ([]ModifyCommand, map[string]
|
||||
}
|
||||
|
||||
var commands []ModifyCommand
|
||||
modifiers := make(map[string]interface{})
|
||||
variables := make(map[string]interface{})
|
||||
|
||||
// Extract top-level modifiers
|
||||
if len(tomlData.Modifiers) > 0 {
|
||||
loadTomlCommandLogger.Debug("Found %d top-level modifiers", len(tomlData.Modifiers))
|
||||
for k, v := range tomlData.Modifiers {
|
||||
modifiers[k] = v
|
||||
// Extract top-level variables
|
||||
if len(tomlData.Variables) > 0 {
|
||||
loadTomlCommandLogger.Debug("Found %d top-level variables", len(tomlData.Variables))
|
||||
for k, v := range tomlData.Variables {
|
||||
variables[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,10 +503,10 @@ func LoadCommandsFromTomlFile(tomlFileData []byte) ([]ModifyCommand, map[string]
|
||||
}
|
||||
}
|
||||
|
||||
loadTomlCommandLogger.Debug("Successfully unmarshaled %d commands and %d modifiers", len(commands), len(modifiers))
|
||||
loadTomlCommandLogger.Debug("Successfully unmarshaled %d commands and %d variables", len(commands), len(variables))
|
||||
loadTomlCommandLogger.Trace("Unmarshaled commands: %v", commands)
|
||||
loadTomlCommandLogger.Trace("Unmarshaled modifiers: %v", modifiers)
|
||||
return commands, modifiers, nil
|
||||
loadTomlCommandLogger.Trace("Unmarshaled variables: %v", variables)
|
||||
return commands, variables, nil
|
||||
}
|
||||
|
||||
// ConvertYAMLToTOML converts YAML files to TOML format
|
||||
@@ -502,20 +514,6 @@ func ConvertYAMLToTOML(yamlPattern string) error {
|
||||
convertLogger := modifyCommandLogger.WithPrefix("ConvertYAMLToTOML").WithField("pattern", yamlPattern)
|
||||
convertLogger.Debug("Starting YAML to TOML conversion")
|
||||
|
||||
// Load YAML commands
|
||||
yamlCommands, err := LoadCommandsFromCookFiles(yamlPattern)
|
||||
if err != nil {
|
||||
convertLogger.Error("Failed to load YAML commands: %v", err)
|
||||
return fmt.Errorf("failed to load YAML commands: %w", err)
|
||||
}
|
||||
|
||||
if len(yamlCommands) == 0 {
|
||||
convertLogger.Info("No YAML commands found for pattern: %s", yamlPattern)
|
||||
return nil
|
||||
}
|
||||
|
||||
convertLogger.Debug("Loaded %d commands from YAML", len(yamlCommands))
|
||||
|
||||
// Find all YAML files matching the pattern
|
||||
static, pattern := SplitPattern(yamlPattern)
|
||||
yamlFiles, err := doublestar.Glob(os.DirFS(static), pattern)
|
||||
@@ -526,6 +524,11 @@ func ConvertYAMLToTOML(yamlPattern string) error {
|
||||
|
||||
convertLogger.Debug("Found %d YAML files to convert", len(yamlFiles))
|
||||
|
||||
if len(yamlFiles) == 0 {
|
||||
convertLogger.Info("No YAML files found for pattern: %s", yamlPattern)
|
||||
return nil
|
||||
}
|
||||
|
||||
conversionCount := 0
|
||||
skippedCount := 0
|
||||
|
||||
@@ -553,14 +556,14 @@ func ConvertYAMLToTOML(yamlPattern string) error {
|
||||
}
|
||||
|
||||
// Load YAML commands from this specific file
|
||||
fileCommands, err := LoadCommandsFromCookFile(yamlData)
|
||||
fileCommands, fileVariables, err := LoadCommandsFromCookFile(yamlData)
|
||||
if err != nil {
|
||||
convertLogger.Error("Failed to parse YAML file %s: %v", yamlFilePath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Convert to TOML structure
|
||||
tomlData, err := convertCommandsToTOML(fileCommands)
|
||||
tomlData, err := convertCommandsToTOML(fileCommands, fileVariables)
|
||||
if err != nil {
|
||||
convertLogger.Error("Failed to convert commands to TOML for %s: %v", yamlFilePath, err)
|
||||
continue
|
||||
@@ -582,15 +585,17 @@ func ConvertYAMLToTOML(yamlPattern string) error {
|
||||
}
|
||||
|
||||
// convertCommandsToTOML converts a slice of ModifyCommand to TOML format
|
||||
func convertCommandsToTOML(commands []ModifyCommand) ([]byte, error) {
|
||||
func convertCommandsToTOML(commands []ModifyCommand, variables map[string]interface{}) ([]byte, error) {
|
||||
convertLogger := modifyCommandLogger.WithPrefix("convertCommandsToTOML")
|
||||
convertLogger.Debug("Converting %d commands to TOML format", len(commands))
|
||||
|
||||
// Create TOML structure
|
||||
tomlData := struct {
|
||||
Commands []ModifyCommand `toml:"commands"`
|
||||
Variables map[string]interface{} `toml:"variables,omitempty"`
|
||||
Commands []ModifyCommand `toml:"commands"`
|
||||
}{
|
||||
Commands: commands,
|
||||
Variables: variables,
|
||||
Commands: commands,
|
||||
}
|
||||
|
||||
// Marshal to TOML
|
||||
@@ -600,6 +605,6 @@ func convertCommandsToTOML(commands []ModifyCommand) ([]byte, error) {
|
||||
return nil, fmt.Errorf("failed to marshal commands to TOML: %w", err)
|
||||
}
|
||||
|
||||
convertLogger.Debug("Successfully converted %d commands to TOML (%d bytes)", len(commands), len(tomlBytes))
|
||||
convertLogger.Debug("Successfully converted %d commands and %d variables to TOML (%d bytes)", len(commands), len(variables), len(tomlBytes))
|
||||
return tomlBytes, nil
|
||||
}
|
||||
|
||||
@@ -281,16 +281,17 @@ func TestAggregateGlobs(t *testing.T) {
|
||||
func TestLoadCommandsFromCookFileSuccess(t *testing.T) {
|
||||
// Arrange
|
||||
yamlData := []byte(`
|
||||
- name: command1
|
||||
regex: "*.txt"
|
||||
lua: replace
|
||||
- name: command2
|
||||
regex: "*.go"
|
||||
lua: delete
|
||||
commands:
|
||||
- name: command1
|
||||
regex: "*.txt"
|
||||
lua: replace
|
||||
- name: command2
|
||||
regex: "*.go"
|
||||
lua: delete
|
||||
`)
|
||||
|
||||
// Act
|
||||
commands, err := LoadCommandsFromCookFile(yamlData)
|
||||
commands, _, err := LoadCommandsFromCookFile(yamlData)
|
||||
|
||||
// Assert
|
||||
assert.NoError(t, err)
|
||||
@@ -308,17 +309,18 @@ func TestLoadCommandsFromCookFileWithComments(t *testing.T) {
|
||||
// Arrange
|
||||
yamlData := []byte(`
|
||||
# This is a comment
|
||||
- name: command1
|
||||
regex: "*.txt"
|
||||
lua: replace
|
||||
# Another comment
|
||||
- name: command2
|
||||
regex: "*.go"
|
||||
lua: delete
|
||||
commands:
|
||||
- name: command1
|
||||
regex: "*.txt"
|
||||
lua: replace
|
||||
# Another comment
|
||||
- name: command2
|
||||
regex: "*.go"
|
||||
lua: delete
|
||||
`)
|
||||
|
||||
// Act
|
||||
commands, err := LoadCommandsFromCookFile(yamlData)
|
||||
commands, _, err := LoadCommandsFromCookFile(yamlData)
|
||||
|
||||
// Assert
|
||||
assert.NoError(t, err)
|
||||
@@ -334,10 +336,10 @@ func TestLoadCommandsFromCookFileWithComments(t *testing.T) {
|
||||
// Handle different YAML formatting styles (flow vs block)
|
||||
func TestLoadCommandsFromCookFileWithFlowStyle(t *testing.T) {
|
||||
// Arrange
|
||||
yamlData := []byte(`[ { name: command1, regex: "*.txt", lua: replace }, { name: command2, regex: "*.go", lua: delete } ]`)
|
||||
yamlData := []byte(`commands: [ { name: command1, regex: "*.txt", lua: replace }, { name: command2, regex: "*.go", lua: delete } ]`)
|
||||
|
||||
// Act
|
||||
commands, err := LoadCommandsFromCookFile(yamlData)
|
||||
commands, _, err := LoadCommandsFromCookFile(yamlData)
|
||||
|
||||
// Assert
|
||||
assert.NoError(t, err)
|
||||
@@ -357,8 +359,8 @@ func TestLoadCommandsFromCookFileNilOrEmptyData(t *testing.T) {
|
||||
emptyData := []byte{}
|
||||
|
||||
// Act
|
||||
commandsNil, errNil := LoadCommandsFromCookFile(nilData)
|
||||
commandsEmpty, errEmpty := LoadCommandsFromCookFile(emptyData)
|
||||
commandsNil, _, errNil := LoadCommandsFromCookFile(nilData)
|
||||
commandsEmpty, _, errEmpty := LoadCommandsFromCookFile(emptyData)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, errNil)
|
||||
@@ -373,7 +375,7 @@ func TestLoadCommandsFromCookFileEmptyData(t *testing.T) {
|
||||
yamlData := []byte(``)
|
||||
|
||||
// Act
|
||||
commands, err := LoadCommandsFromCookFile(yamlData)
|
||||
commands, _, err := LoadCommandsFromCookFile(yamlData)
|
||||
|
||||
// Assert
|
||||
assert.NoError(t, err)
|
||||
@@ -384,19 +386,20 @@ func TestLoadCommandsFromCookFileEmptyData(t *testing.T) {
|
||||
func TestLoadCommandsFromCookFileWithMultipleEntries(t *testing.T) {
|
||||
// Arrange
|
||||
yamlData := []byte(`
|
||||
- name: command1
|
||||
regex: "*.txt"
|
||||
lua: replace
|
||||
- name: command2
|
||||
regex: "*.go"
|
||||
lua: delete
|
||||
- name: command3
|
||||
regex: "*.md"
|
||||
lua: append
|
||||
commands:
|
||||
- name: command1
|
||||
regex: "*.txt"
|
||||
lua: replace
|
||||
- name: command2
|
||||
regex: "*.go"
|
||||
lua: delete
|
||||
- name: command3
|
||||
regex: "*.md"
|
||||
lua: append
|
||||
`)
|
||||
|
||||
// Act
|
||||
commands, err := LoadCommandsFromCookFile(yamlData)
|
||||
commands, _, err := LoadCommandsFromCookFile(yamlData)
|
||||
|
||||
// Assert
|
||||
assert.NoError(t, err)
|
||||
@@ -415,26 +418,27 @@ func TestLoadCommandsFromCookFileWithMultipleEntries(t *testing.T) {
|
||||
func TestLoadCommandsFromCookFileLegitExample(t *testing.T) {
|
||||
// Arrange
|
||||
yamlData := []byte(`
|
||||
- name: crewlayabout
|
||||
pattern: '<Talent identifier="crewlayabout">!anyvalue="(?<repairspeedpenalty>!num)"!anyvalue="(?<skillpenalty>!num)"!anyvalue="(?<repairspeedbonus>!num)"!anyvalue="(?<skillbonus>!num)"!anydistance="(?<distance>!num)"!anySkillBonus!anyvalue="(?<skillpenaltyv>!num)"!anyvalue="(?<skillpenaltyv1>!num)"!anyvalue="(?<skillpenaltyv2>!num)"!anyvalue="(?<skillpenaltyv3>!num)"!anyvalue="(?<skillpenaltyv4>!num)"!anyvalue="(?<repairspeedpenaltyv>!num)'
|
||||
lua: |
|
||||
repairspeedpenalty=round(repairspeedpenalty/2, 2)
|
||||
skillpenalty=round(skillpenalty/2, 0)
|
||||
repairspeedbonus=round(repairspeedbonus*2, 2)
|
||||
skillbonus=round(skillbonus*2, 0)
|
||||
distance=round(distance*2, 0)
|
||||
skillpenaltyv=skillpenalty
|
||||
skillpenaltyv1=skillpenalty
|
||||
skillpenaltyv2=skillpenalty
|
||||
skillpenaltyv3=skillpenalty
|
||||
skillpenaltyv4=skillpenalty
|
||||
repairspeedpenaltyv=round(-repairspeedpenalty/100, 2)
|
||||
files:
|
||||
- '**/TalentsAssistant.xml'
|
||||
commands:
|
||||
- name: crewlayabout
|
||||
pattern: '<Talent identifier="crewlayabout">!anyvalue="(?<repairspeedpenalty>!num)"!anyvalue="(?<skillpenalty>!num)"!anyvalue="(?<repairspeedbonus>!num)"!anyvalue="(?<skillbonus>!num)"!anydistance="(?<distance>!num)"!anySkillBonus!anyvalue="(?<skillpenaltyv>!num)"!anyvalue="(?<skillpenaltyv1>!num)"!anyvalue="(?<skillpenaltyv2>!num)"!anyvalue="(?<skillpenaltyv3>!num)"!anyvalue="(?<skillpenaltyv4>!num)"!anyvalue="(?<repairspeedpenaltyv>!num)'
|
||||
lua: |
|
||||
repairspeedpenalty=round(repairspeedpenalty/2, 2)
|
||||
skillpenalty=round(skillpenalty/2, 0)
|
||||
repairspeedbonus=round(repairspeedbonus*2, 2)
|
||||
skillbonus=round(skillbonus*2, 0)
|
||||
distance=round(distance*2, 0)
|
||||
skillpenaltyv=skillpenalty
|
||||
skillpenaltyv1=skillpenalty
|
||||
skillpenaltyv2=skillpenalty
|
||||
skillpenaltyv3=skillpenalty
|
||||
skillpenaltyv4=skillpenalty
|
||||
repairspeedpenaltyv=round(-repairspeedpenalty/100, 2)
|
||||
files:
|
||||
- '**/TalentsAssistant.xml'
|
||||
`)
|
||||
|
||||
// Act
|
||||
commands, err := LoadCommandsFromCookFile(yamlData)
|
||||
commands, _, err := LoadCommandsFromCookFile(yamlData)
|
||||
|
||||
// Assert
|
||||
assert.NoError(t, err)
|
||||
@@ -543,7 +547,7 @@ func TestLoadCommandsFromCookFilesNoYamlFiles(t *testing.T) {
|
||||
}
|
||||
|
||||
// Execute function
|
||||
commands, err := LoadCommandsFromCookFiles("")
|
||||
commands, _, err := LoadCommandsFromCookFiles("")
|
||||
|
||||
// Assertions
|
||||
if err != nil {
|
||||
@@ -609,7 +613,7 @@ func TestLoadCommandsFromCookFilesNoYamlFiles(t *testing.T) {
|
||||
// }
|
||||
//
|
||||
// // Execute function
|
||||
// commands, err := LoadCommandsFromCookFiles("")
|
||||
// commands, _, err := LoadCommandsFromCookFiles("")
|
||||
//
|
||||
// // Assertions
|
||||
// if err != nil {
|
||||
@@ -693,7 +697,7 @@ func TestLoadCommandsFromCookFilesNoYamlFiles(t *testing.T) {
|
||||
// }
|
||||
//
|
||||
// // Execute function
|
||||
// commands, err := LoadCommandsFromCookFiles("")
|
||||
// commands, _, err := LoadCommandsFromCookFiles("")
|
||||
//
|
||||
// // Assertions
|
||||
// if err != nil {
|
||||
@@ -852,7 +856,7 @@ func TestExpandGlobsMemoization(t *testing.T) {
|
||||
// }
|
||||
//
|
||||
// // Execute function
|
||||
// commands, err := LoadCommandsFromCookFiles("")
|
||||
// commands, _, err := LoadCommandsFromCookFiles("")
|
||||
//
|
||||
// // Assertions
|
||||
// if err == nil {
|
||||
@@ -919,7 +923,7 @@ func TestExpandGlobsMemoization(t *testing.T) {
|
||||
// }
|
||||
//
|
||||
// // Execute function
|
||||
// commands, err := LoadCommandsFromCookFiles("")
|
||||
// commands, _, err := LoadCommandsFromCookFiles("")
|
||||
//
|
||||
// // Assertions
|
||||
// if err != nil {
|
||||
@@ -989,7 +993,7 @@ func TestExpandGlobsMemoization(t *testing.T) {
|
||||
// }
|
||||
//
|
||||
// // Execute function
|
||||
// commands, err := LoadCommandsFromCookFiles("")
|
||||
// commands, _, err := LoadCommandsFromCookFiles("")
|
||||
//
|
||||
// // Assertions
|
||||
// if err != nil {
|
||||
@@ -1047,7 +1051,7 @@ func TestExpandGlobsMemoization(t *testing.T) {
|
||||
// }
|
||||
//
|
||||
// // Execute function
|
||||
// commands, err := LoadCommandsFromCookFiles("")
|
||||
// commands, _, err := LoadCommandsFromCookFiles("")
|
||||
//
|
||||
// // Assertions
|
||||
// if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user