From 024535de6f8bd748ed7b067cdddae1e30ff4999e Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Tue, 1 Oct 2024 20:09:54 +0200 Subject: [PATCH] modify base signature of 'generateCommands' to avoid overused variables --- proxy/debug.go | 4 ++-- proxy/set.go | 2 +- proxy/unset.go | 2 +- proxy/util.go | 12 +++++++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/proxy/debug.go b/proxy/debug.go index 45a12c2..bac5a74 100644 --- a/proxy/debug.go +++ b/proxy/debug.go @@ -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)) } diff --git a/proxy/set.go b/proxy/set.go index 4621165..b4778e3 100644 --- a/proxy/set.go +++ b/proxy/set.go @@ -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) } diff --git a/proxy/unset.go b/proxy/unset.go index 425c41f..7dc21b8 100644 --- a/proxy/unset.go +++ b/proxy/unset.go @@ -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) } diff --git a/proxy/util.go b/proxy/util.go index 3569977..5da197d 100644 --- a/proxy/util.go +++ b/proxy/util.go @@ -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})