From e81b88fb94b7de7d90aeb9f356ce1af8e02193c7 Mon Sep 17 00:00:00 2001 From: Wu Haotian Date: Sat, 29 Feb 2020 17:48:26 +0800 Subject: [PATCH] Feature: add configuration test command (#524) --- main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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()) }