Rework variables to not be commands...

This commit is contained in:
2025-12-19 11:30:28 +01:00
parent a18573c9f8
commit 09cdc91761
4 changed files with 83 additions and 84 deletions

21
main.go
View File

@@ -190,29 +190,16 @@ func runModifier(args []string, cmd *cobra.Command) {
// Load all commands
mainLogger.Debug("Loading commands from arguments")
mainLogger.Trace("Arguments: %v", args)
commands, err := utils.LoadCommands(args)
commands, modifiers, err := utils.LoadCommands(args)
if err != nil || len(commands) == 0 {
mainLogger.Error("Failed to load commands: %v", err)
cmd.Usage()
return
}
// Collect global modifiers from special entries and filter them out
vars := map[string]interface{}{}
filtered := make([]utils.ModifyCommand, 0, len(commands))
for _, c := range commands {
if len(c.Modifiers) > 0 && c.Name == "" && c.Regex == "" && len(c.Regexes) == 0 && c.Lua == "" && len(c.Files) == 0 {
for k, v := range c.Modifiers {
vars[k] = v
}
continue
}
filtered = append(filtered, c)
if len(modifiers) > 0 {
mainLogger.Info("Loaded %d global modifiers", len(modifiers))
processor.SetVariables(modifiers)
}
if len(vars) > 0 {
mainLogger.Info("Loaded %d global modifiers", len(vars))
processor.SetVariables(vars)
}
commands = filtered
mainLogger.Info("Loaded %d commands", len(commands))
if filterFlag != "" {