modify base signature of 'generateCommands' to avoid overused variables

This commit is contained in:
Baipyrus 2024-10-01 20:09:54 +02:00
parent 9eb5982bb7
commit 024535de6f
4 changed files with 13 additions and 7 deletions

View File

@ -51,12 +51,12 @@ func Debug(cfgPath string) {
fmt.Printf("Loading commands for '%s':\n", config.Name)
// Debug Proxy Set Commands
setCmds := generateCommands(config.Set, configCmd, "[PROXY PLACEHOLDER]")
setCmds := generateCommands(configCmd, config.Set, "[PROXY PLACEHOLDER]")
fmt.Println("Set Commands:")
fmt.Printf("%s\n", mapCmdsToStr(setCmds))
// Debug Proxy Unset Commands
unsetCmds := generateCommands(config.Unset, configCmd, "")
unsetCmds := generateCommands(configCmd, config.Unset, "")
fmt.Println("Unset Commands:")
fmt.Printf("%s\n\n", mapCmdsToStr(unsetCmds))
}

View File

@ -21,7 +21,7 @@ func Set(cfgPath string) {
configCmd = config.Cmd
}
commands := generateCommands(config.Set, configCmd, proxy.Server)
commands := generateCommands(configCmd, config.Set, proxy.Server)
util.ExecCmds(commands, stdin)
}

View File

@ -21,7 +21,7 @@ func Unset(cfgPath string) {
configCmd = config.Cmd
}
commands := generateCommands(config.Unset, configCmd, "")
commands := generateCommands(configCmd, config.Unset, "")
util.ExecCmds(commands, stdin)
}

View File

@ -55,14 +55,20 @@ func injectProxy(configArgs []string, configCmd, proxyServer string, variant *ut
return configArgs, configCmd
}
func generateCommands(variants []*util.Variant, configCmd, proxyServer string) []*util.Command {
func generateCommands(base string, variants []*util.Variant, proxyServer string) []*util.Command {
var commands []*util.Command
// Generate one command per variant
// Iterate through all variants and generate a command for each
for _, variant := range variants {
isVariableType := variant.Type == util.VARIABLE
configArgs, configCmd := processVars(isVariableType, variant.Arguments, configCmd)
// Create command from default parameters
cmd := &util.Command{
Name: base,
Arguments: append([]string{}, variant.Arguments...),
}
configArgs, configCmd := processVars(isVariableType, cmd.Arguments, cmd.Name)
configArgs, configCmd = injectProxy(configArgs, configCmd, proxyServer, variant)
commands = append(commands, &util.Command{Name: configCmd, Arguments: configArgs})