diff --git a/main.go b/main.go index 9e545e02..ec705b6e 100644 --- a/main.go +++ b/main.go @@ -10,13 +10,16 @@ import ( "syscall" "github.com/Dreamacro/clash/config" + "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant" "github.com/Dreamacro/clash/hub" + "github.com/Dreamacro/clash/hub/executor" "github.com/Dreamacro/clash/log" ) var ( version bool + testConfig bool homeDir string configFile string ) @@ -25,6 +28,7 @@ func init() { flag.StringVar(&homeDir, "d", "", "set configuration directory") flag.StringVar(&configFile, "f", "", "specify configuration file") flag.BoolVar(&version, "v", false, "show current version of clash") + flag.BoolVar(&testConfig, "t", false, "test configuration and exit") flag.Parse() } @@ -57,6 +61,16 @@ func main() { log.Fatalln("Initial configuration directory error: %s", err.Error()) } + if testConfig { + if _, err := executor.Parse(); err != nil { + log.Errorln(err.Error()) + fmt.Printf("configuration file %s test failed\n", constant.Path.Config()) + os.Exit(1) + } + fmt.Printf("configuration file %s test is successful\n", constant.Path.Config()) + return + } + if err := hub.Parse(); err != nil { log.Fatalln("Parse config error: %s", err.Error()) }