Dump a basic "config" to example usage on failed command
This commit is contained in:
47
main.go
47
main.go
@@ -12,6 +12,7 @@ import (
|
|||||||
"cook/utils"
|
"cook/utils"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||||
)
|
)
|
||||||
@@ -63,8 +64,9 @@ func main() {
|
|||||||
// The plan is:
|
// The plan is:
|
||||||
// Load all commands
|
// Load all commands
|
||||||
commands, err := utils.LoadCommands(args)
|
commands, err := utils.LoadCommands(args)
|
||||||
if err != nil {
|
if err != nil || len(commands) == 0 {
|
||||||
logger.Error("Failed to load commands: %v", err)
|
logger.Error("Failed to load commands: %v", err)
|
||||||
|
CreateExampleConfig()
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -250,6 +252,49 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateExampleConfig() {
|
||||||
|
commands := []utils.ModifyCommand{
|
||||||
|
{
|
||||||
|
Name: "DoubleNumericValues",
|
||||||
|
Regex: "<value>(\\d+)</value>",
|
||||||
|
Lua: "v1 * 2",
|
||||||
|
Files: []string{"data/*.xml"},
|
||||||
|
LogLevel: "INFO",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "UpdatePrices",
|
||||||
|
Regex: "price=\"(\\d+)\"",
|
||||||
|
Lua: "if num(v1) < 100 then return v1 * 1.5 else return v1 end",
|
||||||
|
Files: []string{"items/*.xml", "shop/*.xml"},
|
||||||
|
Git: true,
|
||||||
|
LogLevel: "DEBUG",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "IsolatedTagUpdate",
|
||||||
|
Regex: "<tag>(.*?)</tag>",
|
||||||
|
Lua: "string.upper(s1)",
|
||||||
|
Files: []string{"config.xml"},
|
||||||
|
Isolate: true,
|
||||||
|
NoDedup: true,
|
||||||
|
LogLevel: "TRACE",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := yaml.Marshal(commands)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Failed to marshal example config: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile("example_cook.yml", data, 0644)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Failed to write example_cook.yml: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("Wrote example_cook.yml")
|
||||||
|
}
|
||||||
|
|
||||||
func RunOtherCommands(file string, fileDataStr string, association utils.FileCommandAssociation, fileMutex *sync.Mutex, commandLoggers map[string]*logger.Logger) (string, error) {
|
func RunOtherCommands(file string, fileDataStr string, association utils.FileCommandAssociation, fileMutex *sync.Mutex, commandLoggers map[string]*logger.Logger) (string, error) {
|
||||||
// Aggregate all the modifications and execute them
|
// Aggregate all the modifications and execute them
|
||||||
modifications := []utils.ReplaceCommand{}
|
modifications := []utils.ReplaceCommand{}
|
||||||
|
Reference in New Issue
Block a user