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