ProxySwitcher/proxy/debug.go

66 lines
1.5 KiB
Go
Raw Normal View History

//go:build windows
package proxy
import (
2024-09-16 12:23:04 +00:00
"errors"
"fmt"
2024-09-16 12:23:04 +00:00
"os"
"path/filepath"
"strings"
"github.com/Baipyrus/ProxySwitcher/util"
)
func mapCmdsToStr(commands []*util.Command) string {
var output []string
for _, command := range commands {
cmdArgs := strings.Join(command.Arguments, " ")
cmdStr := fmt.Sprintf("%s %s", command.Name, cmdArgs)
output = append(output, cmdStr)
}
return strings.Join(output, "\n")
}
func Debug(cfgPath string) {
path, _ := filepath.Abs(cfgPath)
2024-09-16 12:23:04 +00:00
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
path = "[N/A]"
}
fmt.Printf("\nConfig:\n")
fmt.Printf("%s\n\n", path)
proxy, _ := ReadSystemProxy()
proxyServer := proxy.Server
if proxyServer == "" {
proxyServer = "[N/A]"
}
2024-09-16 12:23:04 +00:00
fmt.Println("System Proxy:")
fmt.Printf("Enabled: %t\n", proxy.Enabled)
fmt.Printf("Server: %s\n\n", proxyServer)
configs, _ := util.ReadConfigs(cfgPath)
for _, config := range configs {
configCmd := config.Name
// Use command instead of name, if given
if config.Cmd != "" {
configCmd = config.Cmd
}
fmt.Printf("Loading commands for '%s':\n", config.Name)
// Debug Proxy Set Commands
setCmds := generateCommands(configCmd, config.Set, "[PROXY PLACEHOLDER]")
fmt.Println("Set Commands:")
fmt.Printf("%s\n", mapCmdsToStr(setCmds))
// Debug Proxy Unset Commands
unsetCmds := generateCommands(configCmd, config.Unset, "")
fmt.Println("Unset Commands:")
fmt.Printf("%s\n\n", mapCmdsToStr(unsetCmds))
}
}