Add more examples to the configuration file generator
This commit is contained in:
101
main.go
101
main.go
@@ -391,29 +391,100 @@ func CreateExampleConfig() {
|
||||
createExampleConfigLogger := logger.Default.WithPrefix("CreateExampleConfig")
|
||||
createExampleConfigLogger.Debug("Creating example configuration file")
|
||||
commands := []utils.ModifyCommand{
|
||||
// Global modifiers only entry (no name/regex/lua/files)
|
||||
{
|
||||
Name: "DoubleNumericValues",
|
||||
Regex: "<value>(\\d+)<\\/value>",
|
||||
Lua: "v1 * 2",
|
||||
Files: []string{"data/*.xml"},
|
||||
LogLevel: "INFO",
|
||||
Modifiers: map[string]interface{}{
|
||||
"foobar": 4,
|
||||
"multiply": 1.5,
|
||||
"prefix": "NEW_",
|
||||
"enabled": true,
|
||||
},
|
||||
},
|
||||
// Multi-regex example using $variable in Lua
|
||||
{
|
||||
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"},
|
||||
Name: "RFToolsMultiply",
|
||||
Regexes: []string{"generatePerTick = !num", "ticksPer\\w+ = !num", "generatorRFPerTick = !num"},
|
||||
Lua: "* $foobar",
|
||||
Files: []string{"polymc/instances/**/rftools*.toml", `polymc\\instances\\**\\rftools*.toml`},
|
||||
Reset: true,
|
||||
// LogLevel defaults to INFO
|
||||
},
|
||||
// Named capture groups with arithmetic and string ops
|
||||
{
|
||||
Name: "UpdateAmountsAndItems",
|
||||
Regex: `(?P<amount>!num)\s+units\s+of\s+(?P<item>[A-Za-z_\-]+)`,
|
||||
Lua: `amount = amount * $multiply; item = upper(item); return true`,
|
||||
Files: []string{"data/**/*.txt"},
|
||||
// INFO log level
|
||||
},
|
||||
// Full replacement via Lua 'replacement' variable
|
||||
{
|
||||
Name: "BumpMinorVersion",
|
||||
Regex: `version\s*=\s*"(?P<major>!num)\.(?P<minor>!num)\.(?P<patch>!num)"`,
|
||||
Lua: `replacement = format("version=\"%s.%s.%s\"", major, num(minor)+1, 0); return true`,
|
||||
Files: []string{"config/*.ini", "config/*.cfg"},
|
||||
},
|
||||
// Multiline regex example (DOTALL is auto-enabled). Captures numeric in nested XML.
|
||||
{
|
||||
Name: "XMLNestedValueMultiply",
|
||||
Regex: `
|
||||
<item>\s*
|
||||
\s*<name>!any</name>\s*
|
||||
\s*<value>(!num)</value>\s*
|
||||
</item>`,
|
||||
Lua: `* $multiply`,
|
||||
Files: []string{"data/**/*.xml"},
|
||||
// Demonstrates multiline regex in YAML
|
||||
},
|
||||
// Multiline regexES array, with different patterns handled by same Lua
|
||||
{
|
||||
Name: "MultiLinePatterns",
|
||||
Regexes: []string{
|
||||
`<entry>\s*\n\s*<id>(?P<id>!num)</id>\s*\n\s*<score>(?P<score>!num)</score>\s*\n\s*</entry>`,
|
||||
`\[block\]\nkey=(?P<key>[A-Za-z_]+)\nvalue=(?P<val>!num)`,
|
||||
},
|
||||
Lua: `if is_number(score) then score = score * 2 end; if is_number(val) then val = val * 3 end; return true`,
|
||||
Files: []string{"examples/**/*.*"},
|
||||
LogLevel: "DEBUG",
|
||||
},
|
||||
// Use equals operator shorthand and boolean variable
|
||||
{
|
||||
Name: "IsolatedTagUpdate",
|
||||
Regex: "<tag>(.*?)<\\/tag>",
|
||||
Lua: "string.upper(s1)",
|
||||
Files: []string{"config.xml"},
|
||||
Isolate: true,
|
||||
NoDedup: true,
|
||||
Name: "EnableFlags",
|
||||
Regex: `enabled\s*=\s*(true|false)`,
|
||||
Lua: `= $enabled`,
|
||||
Files: []string{"**/*.toml"},
|
||||
},
|
||||
// Demonstrate NoDedup to allow overlapping replacements
|
||||
{
|
||||
Name: "OverlappingGroups",
|
||||
Regex: `(?P<a>!num)(?P<b>!num)`,
|
||||
Lua: `a = num(a) + 1; b = num(b) + 1; return true`,
|
||||
Files: []string{"overlap/**/*.txt"},
|
||||
NoDedup: true,
|
||||
},
|
||||
// Isolate command example operating on entire matched block
|
||||
{
|
||||
Name: "IsolateUppercaseBlock",
|
||||
Regex: `BEGIN\n(?P<block>!any)\nEND`,
|
||||
Lua: `block = upper(block); return true`,
|
||||
Files: []string{"logs/**/*.log"},
|
||||
Isolate: true,
|
||||
LogLevel: "TRACE",
|
||||
},
|
||||
// Using !rep placeholder and arrays of files
|
||||
{
|
||||
Name: "RepeatPlaceholderExample",
|
||||
Regex: `name: (.*) !rep(, .* , 2)`,
|
||||
Lua: `-- no-op, just demonstrate placeholder; return false`,
|
||||
Files: []string{"lists/**/*.yml", "lists/**/*.yaml"},
|
||||
},
|
||||
// Using string variable in Lua expression
|
||||
{
|
||||
Name: "PrefixKeys",
|
||||
Regex: `(?P<key>[A-Za-z0-9_]+)\s*=`,
|
||||
Lua: `key = $prefix .. key; return true`,
|
||||
Files: []string{"**/*.properties"},
|
||||
},
|
||||
}
|
||||
|
||||
data, err := yaml.Marshal(commands)
|
||||
|
Reference in New Issue
Block a user