add config detection to debug command

This commit is contained in:
Baipyrus 2024-09-16 14:23:04 +02:00
parent c66937fdba
commit 2d126e6293

View File

@ -1,7 +1,10 @@
package proxy package proxy
import ( import (
"errors"
"fmt" "fmt"
"os"
"path/filepath"
"strings" "strings"
"github.com/Baipyrus/ProxySwitcher/util" "github.com/Baipyrus/ProxySwitcher/util"
@ -20,13 +23,21 @@ func mapCmdsToStr(commands []*util.Command) string {
} }
func Debug(cfgFile string) { func Debug(cfgFile string) {
path, _ := filepath.Abs(cfgFile)
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() proxy, _ := ReadSystemProxy()
proxyServer := proxy.Server proxyServer := proxy.Server
if proxyServer == "" { if proxyServer == "" {
proxyServer = "[N/A]" proxyServer = "[N/A]"
} }
fmt.Println("\nSystem Proxy:") fmt.Println("System Proxy:")
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)