passing a command by reference to 'processVars' instead of return types

This commit is contained in:
Baipyrus 2024-10-01 20:13:47 +02:00
parent 024535de6f
commit 39a0a6d828

View File

@ -9,21 +9,16 @@ import (
"golang.org/x/sys/windows/registry" "golang.org/x/sys/windows/registry"
) )
func processVars(isVariableType bool, args []string, configCmd string) ([]string, string) { func processVars(cmd *util.Command, isVariableType bool) {
var configArgs []string // If not a variable type, return early as there's nothing to replace
for _, arg := range args {
// If not replacable, append
if !isVariableType { if !isVariableType {
configArgs = append(configArgs, arg) return
continue
} }
// Replace specific "ProxySwitcher Argument" in command // Replace specific $PRSW_ARG in the command's Name with each argument
configCmd = strings.Replace(configCmd, "$PRSW_ARG", arg, 1) for _, arg := range cmd.Arguments {
cmd.Name = strings.Replace(cmd.Name, "$PRSW_ARG", arg, 1)
} }
return configArgs, configCmd
} }
func injectProxy(configArgs []string, configCmd, proxyServer string, variant *util.Variant) ([]string, string) { func injectProxy(configArgs []string, configCmd, proxyServer string, variant *util.Variant) ([]string, string) {
@ -68,8 +63,8 @@ func generateCommands(base string, variants []*util.Variant, proxyServer string)
Arguments: append([]string{}, variant.Arguments...), Arguments: append([]string{}, variant.Arguments...),
} }
configArgs, configCmd := processVars(isVariableType, cmd.Arguments, cmd.Name) processVars(cmd, isVariableType)
configArgs, configCmd = injectProxy(configArgs, configCmd, proxyServer, variant) configArgs, configCmd := injectProxy(cmd.Arguments, cmd.Name, proxyServer, variant)
commands = append(commands, &util.Command{Name: configCmd, Arguments: configArgs}) commands = append(commands, &util.Command{Name: configCmd, Arguments: configArgs})
} }