mirror of
https://github.com/Baipyrus/ProxySwitcher.git
synced 2024-12-26 04:31:45 +00:00
passing config file path through commands to functions
This commit is contained in:
parent
15e81cf2ea
commit
9e72eb5171
@ -10,7 +10,7 @@ var debugCmd = &cobra.Command{
|
|||||||
Use: "debug",
|
Use: "debug",
|
||||||
Short: "Output all parsed configurations for debugging",
|
Short: "Output all parsed configurations for debugging",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
proxy.Debug()
|
proxy.Debug(cfgFile)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ var saveCmd = &cobra.Command{
|
|||||||
var input string
|
var input string
|
||||||
fmt.Print("Save this data? (Y/n) ")
|
fmt.Print("Save this data? (Y/n) ")
|
||||||
if input == "" || strings.ToLower(input) == "y" {
|
if input == "" || strings.ToLower(input) == "y" {
|
||||||
util.SaveConfig(config)
|
util.SaveConfig(cfgFile, config)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ var setCmd = &cobra.Command{
|
|||||||
Use: "set",
|
Use: "set",
|
||||||
Short: "Enable the current internet proxy settings",
|
Short: "Enable the current internet proxy settings",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
proxy.Set()
|
proxy.Set(cfgFile)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ var unsetCmd = &cobra.Command{
|
|||||||
Use: "unset",
|
Use: "unset",
|
||||||
Short: "Disable the current internet proxy settings",
|
Short: "Disable the current internet proxy settings",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
proxy.Unset()
|
proxy.Unset(cfgFile)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ func mapCmdsToStr(commands []*util.Command) string {
|
|||||||
return strings.Join(output, "\n")
|
return strings.Join(output, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debug() {
|
func Debug(cfgFile string) {
|
||||||
proxy, _ := ReadSystemProxy()
|
proxy, _ := ReadSystemProxy()
|
||||||
proxyServer := proxy.Server
|
proxyServer := proxy.Server
|
||||||
if proxyServer == "" {
|
if proxyServer == "" {
|
||||||
@ -30,7 +30,7 @@ func Debug() {
|
|||||||
fmt.Printf("Enabled: %t\n", proxy.Enabled)
|
fmt.Printf("Enabled: %t\n", proxy.Enabled)
|
||||||
fmt.Printf("Server: %s\n\n", proxyServer)
|
fmt.Printf("Server: %s\n\n", proxyServer)
|
||||||
|
|
||||||
configs, _ := util.ReadConfigs()
|
configs, _ := util.ReadConfigs(cfgFile)
|
||||||
for _, config := range configs {
|
for _, config := range configs {
|
||||||
configCmd := config.Name
|
configCmd := config.Name
|
||||||
// Use command instead of name, if given
|
// Use command instead of name, if given
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/Baipyrus/ProxySwitcher/util"
|
"github.com/Baipyrus/ProxySwitcher/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Set() {
|
func Set(cfgFile string) {
|
||||||
stdin, closeFunc, _ := util.ReadyCmd()
|
stdin, closeFunc, _ := util.ReadyCmd()
|
||||||
|
|
||||||
proxy, _ := ReadSystemProxy()
|
proxy, _ := ReadSystemProxy()
|
||||||
@ -13,7 +13,7 @@ func Set() {
|
|||||||
SetSystemProxy(true)
|
SetSystemProxy(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
configs, _ := util.ReadConfigs()
|
configs, _ := util.ReadConfigs(cfgFile)
|
||||||
for _, config := range configs {
|
for _, config := range configs {
|
||||||
configCmd := config.Name
|
configCmd := config.Name
|
||||||
// Use command instead of name, if given
|
// Use command instead of name, if given
|
||||||
|
@ -4,16 +4,16 @@ import (
|
|||||||
"github.com/Baipyrus/ProxySwitcher/util"
|
"github.com/Baipyrus/ProxySwitcher/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Unset() {
|
func Unset(cfgFile string) {
|
||||||
stdin, closeFunc, _ := util.ReadyCmd()
|
stdin, closeFunc, _ := util.ReadyCmd()
|
||||||
|
|
||||||
// Unset system proxy, if not already
|
|
||||||
proxy, _ := ReadSystemProxy()
|
proxy, _ := ReadSystemProxy()
|
||||||
|
// Unset system proxy, if not already
|
||||||
if proxy.Enabled {
|
if proxy.Enabled {
|
||||||
SetSystemProxy(false)
|
SetSystemProxy(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
configs, _ := util.ReadConfigs()
|
configs, _ := util.ReadConfigs(cfgFile)
|
||||||
for _, config := range configs {
|
for _, config := range configs {
|
||||||
configCmd := config.Name
|
configCmd := config.Name
|
||||||
// Use command instead of name, if given
|
// Use command instead of name, if given
|
||||||
|
Loading…
Reference in New Issue
Block a user