From 9e72eb5171051fbca223ae0fde7e43ebcee889ae Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Fri, 13 Sep 2024 00:16:14 +0200 Subject: [PATCH] passing config file path through commands to functions --- cmd/debug.go | 2 +- cmd/save.go | 2 +- cmd/set.go | 2 +- cmd/unset.go | 2 +- proxy/debug.go | 4 ++-- proxy/set.go | 4 ++-- proxy/unset.go | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/debug.go b/cmd/debug.go index 8f991dc..e225a12 100644 --- a/cmd/debug.go +++ b/cmd/debug.go @@ -10,7 +10,7 @@ var debugCmd = &cobra.Command{ Use: "debug", Short: "Output all parsed configurations for debugging", Run: func(cmd *cobra.Command, args []string) { - proxy.Debug() + proxy.Debug(cfgFile) }, } diff --git a/cmd/save.go b/cmd/save.go index e93efb5..56f4e7a 100644 --- a/cmd/save.go +++ b/cmd/save.go @@ -38,7 +38,7 @@ var saveCmd = &cobra.Command{ var input string fmt.Print("Save this data? (Y/n) ") if input == "" || strings.ToLower(input) == "y" { - util.SaveConfig(config) + util.SaveConfig(cfgFile, config) } }, } diff --git a/cmd/set.go b/cmd/set.go index a919588..011ff22 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -10,7 +10,7 @@ var setCmd = &cobra.Command{ Use: "set", Short: "Enable the current internet proxy settings", Run: func(cmd *cobra.Command, args []string) { - proxy.Set() + proxy.Set(cfgFile) }, } diff --git a/cmd/unset.go b/cmd/unset.go index 65a9917..c619448 100644 --- a/cmd/unset.go +++ b/cmd/unset.go @@ -10,7 +10,7 @@ var unsetCmd = &cobra.Command{ Use: "unset", Short: "Disable the current internet proxy settings", Run: func(cmd *cobra.Command, args []string) { - proxy.Unset() + proxy.Unset(cfgFile) }, } diff --git a/proxy/debug.go b/proxy/debug.go index 8430d06..90fe8ec 100644 --- a/proxy/debug.go +++ b/proxy/debug.go @@ -19,7 +19,7 @@ func mapCmdsToStr(commands []*util.Command) string { return strings.Join(output, "\n") } -func Debug() { +func Debug(cfgFile string) { proxy, _ := ReadSystemProxy() proxyServer := proxy.Server if proxyServer == "" { @@ -30,7 +30,7 @@ func Debug() { fmt.Printf("Enabled: %t\n", proxy.Enabled) fmt.Printf("Server: %s\n\n", proxyServer) - configs, _ := util.ReadConfigs() + configs, _ := util.ReadConfigs(cfgFile) for _, config := range configs { configCmd := config.Name // Use command instead of name, if given diff --git a/proxy/set.go b/proxy/set.go index 00c0b7f..a531657 100644 --- a/proxy/set.go +++ b/proxy/set.go @@ -4,7 +4,7 @@ import ( "github.com/Baipyrus/ProxySwitcher/util" ) -func Set() { +func Set(cfgFile string) { stdin, closeFunc, _ := util.ReadyCmd() proxy, _ := ReadSystemProxy() @@ -13,7 +13,7 @@ func Set() { SetSystemProxy(true) } - configs, _ := util.ReadConfigs() + configs, _ := util.ReadConfigs(cfgFile) for _, config := range configs { configCmd := config.Name // Use command instead of name, if given diff --git a/proxy/unset.go b/proxy/unset.go index f4eade3..c24b4b8 100644 --- a/proxy/unset.go +++ b/proxy/unset.go @@ -4,16 +4,16 @@ import ( "github.com/Baipyrus/ProxySwitcher/util" ) -func Unset() { +func Unset(cfgFile string) { stdin, closeFunc, _ := util.ReadyCmd() - // Unset system proxy, if not already proxy, _ := ReadSystemProxy() + // Unset system proxy, if not already if proxy.Enabled { SetSystemProxy(false) } - configs, _ := util.ReadConfigs() + configs, _ := util.ReadConfigs(cfgFile) for _, config := range configs { configCmd := config.Name // Use command instead of name, if given