Minor fixes and tweaks
This commit is contained in:
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@@ -19,6 +19,20 @@
|
|||||||
"**/Outpost*.xml"
|
"**/Outpost*.xml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Launch Package (Barotrauma cookfile)",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${workspaceFolder}",
|
||||||
|
"cwd": "C:/Users/Administrator/Seafile/Games-Barotrauma",
|
||||||
|
"args": [
|
||||||
|
"-loglevel",
|
||||||
|
"trace",
|
||||||
|
"-cook",
|
||||||
|
"cookassistant.yml",
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Launch Package (Workspace)",
|
"name": "Launch Package (Workspace)",
|
||||||
"type": "go",
|
"type": "go",
|
||||||
|
19
main.go
19
main.go
@@ -20,12 +20,15 @@ type GlobalStats struct {
|
|||||||
TotalModifications int
|
TotalModifications int
|
||||||
ProcessedFiles int
|
ProcessedFiles int
|
||||||
FailedFiles int
|
FailedFiles int
|
||||||
|
ModificationsPerCommand map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
repo *git.Repository
|
repo *git.Repository
|
||||||
worktree *git.Worktree
|
worktree *git.Worktree
|
||||||
stats GlobalStats = GlobalStats{}
|
stats GlobalStats = GlobalStats{
|
||||||
|
ModificationsPerCommand: make(map[string]int),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -95,8 +98,6 @@ func main() {
|
|||||||
|
|
||||||
// Add performance tracking
|
// Add performance tracking
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
fileCount := 0
|
|
||||||
modCount := 0
|
|
||||||
var fileMutex sync.Mutex
|
var fileMutex sync.Mutex
|
||||||
|
|
||||||
for file, commands := range associations {
|
for file, commands := range associations {
|
||||||
@@ -127,6 +128,10 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
modifications = append(modifications, commands...)
|
modifications = append(modifications, commands...)
|
||||||
|
// It is not guranteed that all the commands will be executed...
|
||||||
|
// TODO: Make this better
|
||||||
|
// We'd have to pass the map to executemodifications or something...
|
||||||
|
stats.ModificationsPerCommand[command.Name] += len(commands)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(modifications) == 0 {
|
if len(modifications) == 0 {
|
||||||
@@ -138,8 +143,8 @@ func main() {
|
|||||||
fileDataStr, count := utils.ExecuteModifications(modifications, fileDataStr)
|
fileDataStr, count := utils.ExecuteModifications(modifications, fileDataStr)
|
||||||
|
|
||||||
fileMutex.Lock()
|
fileMutex.Lock()
|
||||||
fileCount++
|
stats.ProcessedFiles++
|
||||||
modCount += count
|
stats.TotalModifications += count
|
||||||
fileMutex.Unlock()
|
fileMutex.Unlock()
|
||||||
|
|
||||||
logger.Info("Executed %d modifications for file %q", count, file)
|
logger.Info("Executed %d modifications for file %q", count, file)
|
||||||
@@ -157,8 +162,8 @@ func main() {
|
|||||||
|
|
||||||
processingTime := time.Since(startTime)
|
processingTime := time.Since(startTime)
|
||||||
logger.Info("Processing completed in %v", processingTime)
|
logger.Info("Processing completed in %v", processingTime)
|
||||||
if fileCount > 0 {
|
if stats.ProcessedFiles > 0 {
|
||||||
logger.Info("Average time per file: %v", processingTime/time.Duration(fileCount))
|
logger.Info("Average time per file: %v", processingTime/time.Duration(stats.ProcessedFiles))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Also give each command its own logger, maybe prefix it with something... Maybe give commands a name?
|
// TODO: Also give each command its own logger, maybe prefix it with something... Maybe give commands a name?
|
||||||
|
@@ -5,7 +5,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Deprecated
|
||||||
GitFlag = flag.Bool("git", false, "Use git to manage files")
|
GitFlag = flag.Bool("git", false, "Use git to manage files")
|
||||||
|
// Deprecated
|
||||||
ResetFlag = flag.Bool("reset", false, "Reset files to their original state")
|
ResetFlag = flag.Bool("reset", false, "Reset files to their original state")
|
||||||
LogLevel = flag.String("loglevel", "INFO", "Set log level: ERROR, WARNING, INFO, DEBUG, TRACE")
|
LogLevel = flag.String("loglevel", "INFO", "Set log level: ERROR, WARNING, INFO, DEBUG, TRACE")
|
||||||
Cookfile = flag.String("cook", "**/cook.yml", "Path to cook config files, can be globbed")
|
Cookfile = flag.String("cook", "**/cook.yml", "Path to cook config files, can be globbed")
|
||||||
|
@@ -124,8 +124,11 @@ func LoadCommands(args []string) ([]ModifyCommand, error) {
|
|||||||
logger.Info("Loading commands from arguments: %v", args)
|
logger.Info("Loading commands from arguments: %v", args)
|
||||||
newcommands, err = LoadCommandFromArgs(args)
|
newcommands, err = LoadCommandFromArgs(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if len(commands) == 0 {
|
||||||
return nil, fmt.Errorf("failed to load commands from args: %w", err)
|
return nil, fmt.Errorf("failed to load commands from args: %w", err)
|
||||||
}
|
}
|
||||||
|
logger.Warning("Failed to load commands from args: %v", err)
|
||||||
|
}
|
||||||
logger.Info("Successfully loaded %d commands from args", len(newcommands))
|
logger.Info("Successfully loaded %d commands from args", len(newcommands))
|
||||||
commands = append(commands, newcommands...)
|
commands = append(commands, newcommands...)
|
||||||
logger.Info("Now total commands: %d", len(commands))
|
logger.Info("Now total commands: %d", len(commands))
|
||||||
@@ -166,7 +169,7 @@ func LoadCommandsFromCookFiles(s string) ([]ModifyCommand, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands := []ModifyCommand{}
|
commands := []ModifyCommand{}
|
||||||
cookFiles, err := doublestar.Glob(os.DirFS(cwd), "*.yaml")
|
cookFiles, err := doublestar.Glob(os.DirFS(cwd), *Cookfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to glob cook files: %w", err)
|
return nil, fmt.Errorf("failed to glob cook files: %w", err)
|
||||||
}
|
}
|
||||||
|
@@ -523,6 +523,36 @@ func TestLoadCommandsFromCookFileWithMultipleEntries(t *testing.T) {
|
|||||||
assert.Equal(t, "append", commands[2].Lua)
|
assert.Equal(t, "append", commands[2].Lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'
|
||||||
|
`)
|
||||||
|
|
||||||
|
// Act
|
||||||
|
commands, err := LoadCommandsFromCookFile(yamlData)
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, commands, 1)
|
||||||
|
assert.Equal(t, "crewlayabout", commands[0].Name)
|
||||||
|
}
|
||||||
|
|
||||||
// Valid command with minimum 3 arguments returns a ModifyCommand slice with correct values
|
// Valid command with minimum 3 arguments returns a ModifyCommand slice with correct values
|
||||||
func TestLoadCommandFromArgsWithValidArguments(t *testing.T) {
|
func TestLoadCommandFromArgsWithValidArguments(t *testing.T) {
|
||||||
// Setup
|
// Setup
|
||||||
|
Reference in New Issue
Block a user